Skip to content

Instantly share code, notes, and snippets.

@tav
Created June 8, 2009 22:21
Show Gist options
  • Save tav/126104 to your computer and use it in GitHub Desktop.
Save tav/126104 to your computer and use it in GitHub Desktop.
from decimal import Decimal
def profit(price, current, bid_increase=Decimal('0.15'), bid_price=Decimal('0.75')):
price, current = Decimal(price), Decimal(current)
bids = current / bid_increase
total = (bids * bid_price)
if current < price: current = 0
profit = total - price + current
# print "# of bids:", bids
# print "profit:", profit
return profit
def penny(price, current): return profit(price, current, Decimal('0.01'))
def profit_uk(price, current): return profit(price, current, Decimal('0.07'), Decimal('0.50'))
def penny_uk(price, current): return profit(price, current, Decimal('0.01'), Decimal('0.50'))
def find_profit(penny_auction=False):
if penny_auction:
bid_increase = Decimal('0.01')
else:
bid_increase = Decimal('0.15')
current = raw_input('Current Price: ')
price = raw_input('Product Price: ')
return profit(price, current, bid_increase)
def find_profit_uk(penny_auction=False):
if penny_auction:
bid_increase = Decimal('0.01')
else:
bid_increase = Decimal('0.07')
current = raw_input('Current Price: ')
price = raw_input('Product Price: ')
return profit(price, current, bid_increase, Decimal('0.50'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment