Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def main():
- def balances(msg):
- while True:
- try:
- x = float(raw_input(msg))
- return x
- except ValueError:
- print"That's not a number"
- continue
- from prettytable import PrettyTable
- pt = PrettyTable(['Horse','Stake','Odds','Result','Returns','Book'])
- while True:
- balance = balances('Balance: ')
- print
- bfair_balance = balances('bfair: ')
- wh_balance = balances('wh: ')
- freds_balance = balances('freds: ')
- sky_balance = balances('sky: ')
- pp_balance = balances('pp: ')
- balance_sum = pp_balance + bfair_balance + sky_balance + freds_balance + wh_balance
- if balance == balance_sum:
- break
- else:
- print "Balances do not match"
- print
- print "Balance: %s" %balance
- books = {'bfair': bfair_balance, 'sky':sky_balance, 'wh': wh_balance, 'freds': freds_balance, 'pp': pp_balance}
- print books
- print
- inputs = []
- def r4(x):
- returns = (stake*odds) - (((stake * odds) - stake) * x)
- print "Returns:%f"%returns
- return returns
- while True:
- add_selection =raw_input("Would you like to add a selection? ")
- if add_selection == "Yes":
- print
- selection = raw_input('Horse: ')
- book = raw_input('Book: ')
- while book not in['bfair','sky','wh','freds','pp']:
- print "That's not valid"
- book = raw_input('Book: ')
- for k, v in books.iteritems():
- while k == book and v <=0:
- print "That book has an empty balance"
- book = raw_input('Book: ')
- stake = float(raw_input('Stake: '))
- while stake <=0:
- print "Please enter a stake greater than 0"
- stake = float(raw_input('Stake: '))
- for k, v in books.iteritems():
- while k == book:
- if stake > v:
- print "You do not have sufficient funds"
- stake = float(raw_input('Stake: '))
- while stake <= 0:
- print "Please enter a stake greater than 0"
- stake = float(raw_input('Stake: '))
- if stake <= v:
- odds = float(raw_input('Odds: '))
- while odds <=0:
- print "Please enter odds greater than 0"
- odds = float(raw_input('Odds: '))
- deductions = {'5p' : 0.05, '10p' : 0.10, '15p' : 0.15,'20p': 0.20, '25p' : 0.25 }
- result = (raw_input('Result: '))
- if result == "Win":
- result = result
- rule4 = raw_input("Rule4? Please enter \"Yes\" or \"No\": ")
- if rule4 == "Yes":
- ded = raw_input("Enter rule 4 deduction: " )
- for rl4, t in deductions.iteritems():
- if ded == rl4:
- returns = r4(t)
- print
- v = v - stake + returns
- books[k] = v
- elif rule4 == "No":
- returns = stake * odds
- print "Returns:%f"%returns
- print
- v = v - stake + returns
- books[k] = v
- elif result == "Lose":
- result = result
- returns = 0
- print "Returns:%f"%returns
- print
- v = v - stake + returns
- books[k] = v
- balance = sum(books.itervalues())
- print "Balance:%f" %balance
- print
- print books
- my_list=[selection,stake,odds,result,returns,book]
- inputs.append(my_list)
- print
- total_stake=[]
- for my_list in inputs:
- total_stake.append(my_list[1])
- total_returns = []
- for my_list in inputs:
- total_returns.append(my_list[4])
- print
- pt.add_row([selection,stake,odds,result,returns,book])
- print pt
- break
- elif add_selection == "No":
- print
- print "Total Stake: %f" %sum(total_stake)
- print
- print "Total Returns: %f" %sum(total_returns)
- print
- print "Selections"
- print
- print pt
- break
- import os
- os.system("pause")
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement