Advertisement
Guest User

Untitled

a guest
Sep 20th, 2016
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.32 KB | None | 0 0
  1. def main():
  2. def balances(msg):
  3. while True:
  4. try:
  5. x = float(raw_input(msg))
  6. return x
  7. except ValueError:
  8. print"That's not a number"
  9. continue
  10.  
  11.  
  12. from prettytable import PrettyTable
  13. pt = PrettyTable(['Horse','Stake','Odds','Result','Returns','Book'])
  14.  
  15. while True:
  16. balance = balances('Balance: ')
  17. print
  18. bfair_balance = balances('bfair: ')
  19. wh_balance = balances('wh: ')
  20. freds_balance = balances('freds: ')
  21. sky_balance = balances('sky: ')
  22. pp_balance = balances('pp: ')
  23. balance_sum = pp_balance + bfair_balance + sky_balance + freds_balance + wh_balance
  24. if balance == balance_sum:
  25. break
  26. else:
  27. print "Balances do not match"
  28. print
  29.  
  30. print "Balance: %s" %balance
  31.  
  32. books = {'bfair': bfair_balance, 'sky':sky_balance, 'wh': wh_balance, 'freds': freds_balance, 'pp': pp_balance}
  33. print books
  34.  
  35.  
  36. print
  37.  
  38.  
  39. inputs = []
  40.  
  41. def r4(x):
  42. returns = (stake*odds) - (((stake * odds) - stake) * x)
  43. print "Returns:%f"%returns
  44. return returns
  45.  
  46.  
  47.  
  48. while True:
  49.  
  50.  
  51. add_selection =raw_input("Would you like to add a selection? ")
  52. if add_selection == "Yes":
  53. print
  54. selection = raw_input('Horse: ')
  55.  
  56. book = raw_input('Book: ')
  57.  
  58. while book not in['bfair','sky','wh','freds','pp']:
  59. print "That's not valid"
  60. book = raw_input('Book: ')
  61.  
  62. for k, v in books.iteritems():
  63. while k == book and v <=0:
  64. print "That book has an empty balance"
  65. book = raw_input('Book: ')
  66.  
  67.  
  68.  
  69. stake = float(raw_input('Stake: '))
  70.  
  71. while stake <=0:
  72. print "Please enter a stake greater than 0"
  73. stake = float(raw_input('Stake: '))
  74.  
  75.  
  76. for k, v in books.iteritems():
  77.  
  78. while k == book:
  79.  
  80.  
  81.  
  82. if stake > v:
  83. print "You do not have sufficient funds"
  84. stake = float(raw_input('Stake: '))
  85. while stake <= 0:
  86. print "Please enter a stake greater than 0"
  87. stake = float(raw_input('Stake: '))
  88. if stake <= v:
  89. odds = float(raw_input('Odds: '))
  90. while odds <=0:
  91. print "Please enter odds greater than 0"
  92. odds = float(raw_input('Odds: '))
  93.  
  94.  
  95.  
  96. deductions = {'5p' : 0.05, '10p' : 0.10, '15p' : 0.15,'20p': 0.20, '25p' : 0.25 }
  97.  
  98.  
  99. result = (raw_input('Result: '))
  100. if result == "Win":
  101. result = result
  102. rule4 = raw_input("Rule4? Please enter \"Yes\" or \"No\": ")
  103. if rule4 == "Yes":
  104. ded = raw_input("Enter rule 4 deduction: " )
  105. for rl4, t in deductions.iteritems():
  106. if ded == rl4:
  107. returns = r4(t)
  108. print
  109. v = v - stake + returns
  110. books[k] = v
  111.  
  112. elif rule4 == "No":
  113. returns = stake * odds
  114. print "Returns:%f"%returns
  115. print
  116. v = v - stake + returns
  117. books[k] = v
  118. elif result == "Lose":
  119. result = result
  120. returns = 0
  121. print "Returns:%f"%returns
  122. print
  123. v = v - stake + returns
  124. books[k] = v
  125.  
  126.  
  127.  
  128. balance = sum(books.itervalues())
  129. print "Balance:%f" %balance
  130. print
  131. print books
  132.  
  133. my_list=[selection,stake,odds,result,returns,book]
  134.  
  135. inputs.append(my_list)
  136.  
  137. print
  138. total_stake=[]
  139. for my_list in inputs:
  140. total_stake.append(my_list[1])
  141.  
  142. total_returns = []
  143. for my_list in inputs:
  144. total_returns.append(my_list[4])
  145.  
  146.  
  147. print
  148.  
  149. pt.add_row([selection,stake,odds,result,returns,book])
  150. print pt
  151.  
  152.  
  153. break
  154.  
  155.  
  156.  
  157.  
  158. elif add_selection == "No":
  159.  
  160. print
  161.  
  162.  
  163. print "Total Stake: %f" %sum(total_stake)
  164. print
  165. print "Total Returns: %f" %sum(total_returns)
  166.  
  167.  
  168. print
  169. print "Selections"
  170. print
  171. print pt
  172.  
  173. break
  174.  
  175.  
  176. import os
  177. os.system("pause")
  178.  
  179. if __name__ == '__main__':
  180. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement