Advertisement
Guest User

Untitled

a guest
Apr 20th, 2014
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.58 KB | None | 0 0
  1. from random import *
  2. import random
  3.  
  4. def draw():
  5. #return a list of six randomly picked numbers
  6. numbers=list(range(1,50))
  7. drawn=[]
  8. for n in range (6):
  9. x=randint(0,len(numbers)-1)
  10. no=numbers.pop(x)
  11. drawn.append(no)
  12. return drawn
  13.  
  14. a=int(input("What is your first number? (maximum of 49)"))
  15. b=int(input("What is your second number? (different from 1)"))
  16. c=int(input("What is your third number? (different from 1,2)"))
  17. i=int(input("What is your fourth number?(different from 1,2,3)"))
  18. e=int(input("What is your fith number?(different from 1,2,3,4)"))
  19. f=int(input("What is your sixth number?(different from 1,2,3,4,5)"))
  20.  
  21. def winner():
  22. ticket=[a,b,c,i,e,f]
  23. wins=0
  24. costs=0
  25. while True:
  26. costs=costs+1
  27. d=draw()
  28. matches=0
  29. for h in ticket:
  30. if h in d:
  31. matches=matches+1
  32. if matches==3:
  33. print ("You Matched 3 on try", costs)
  34. elif matches==4:
  35. print ("Cool! 4 matches on try", costs)
  36. elif matches==5:
  37. print ("Amazing!", costs, "trys for 5 matches!")
  38. elif matches==6:
  39. print ("Congratulations! you matched all 6 numbers on try", costs)
  40. return False
  41. draw()
  42. winner()
  43.  
  44. from random import randint, sample
  45.  
  46. # Ontario Lotto 6/49 prize schedule
  47. COST = 0.50
  48. PRIZES = [0, 0, 0, 5., 50., 500., 1000000.]
  49.  
  50. def draw():
  51. return set(sample(range(1, 50), 6))
  52.  
  53. def get_ints(prompt):
  54. while True:
  55. try:
  56. return [int(i) for i in input(prompt).split()]
  57. except ValueError:
  58. pass
  59.  
  60. def pick():
  61. while True:
  62. nums = set(get_ints(
  63. "Please enter 6 numbers in [1..49], ie 3 4 17 22 44 47: "
  64. ))
  65. if len(nums) == 6 and 1 <= min(nums) and max(nums) <= 49:
  66. return nums
  67.  
  68. def num_matched(picked):
  69. return len(picked & draw()) # set intersection
  70.  
  71. def report(matches):
  72. total_cost = COST * sum(matches)
  73. total_won = sum(m*p for m,p in zip(matches, PRIZES))
  74. net = total_won - total_cost
  75. # report on the results:
  76. print("nYou won:")
  77. print(
  78. " nothing {:>8} times -> ${:>12.2f}"
  79. .format(sum(matches[:3]), 0.)
  80. )
  81. for i in range(3, 7):
  82. print(
  83. " ${:>12.2f} {:>8} times -> ${:>12.2f}"
  84. .format(PRIZES[i], matches[i], PRIZES[i] * matches[i])
  85. )
  86. print(
  87. "nYou paid ${:0.2f} to win ${:0.2f}, for a net result of ${:0.2f}."
  88. .format(total_cost, total_won, net)
  89. )
  90.  
  91. def main():
  92. # pick a set of numbers
  93. picked = pick()
  94. # repeat until we have seen 3, 4, 5, and 6-ball matches
  95. matches = [0, 0, 0, 0, 0, 0, 0]
  96. while not all(matches[3:]):
  97. matches[num_matched(picked)] += 1
  98. report(matches)
  99.  
  100. if __name__=="__main__":
  101. main()
  102.  
  103. Please enter 6 numbers in [1..49], ie 3 4 17 22 44 47: 4 6 9 12 14 19
  104.  
  105. You won:
  106. nothing 10060703 times -> $ 0.00
  107. $ 5.00 181218 times -> $ 906090.00
  108. $ 50.00 9888 times -> $ 494400.00
  109. $ 500.00 189 times -> $ 94500.00
  110. $ 1000000.00 1 times -> $ 1000000.00
  111.  
  112. You paid $5125999.50 to win $2494990.00, for a net result of $-2631009.50.
  113.  
  114. ...
  115. costs=0
  116. found = []
  117. while True:
  118. ...
  119. if matches==3 and 3 not in found:
  120. found.append(3)
  121. print ("You Matched 3 on try", costs)
  122. elif matches==4 add 4 not in found:
  123. found.append(4)
  124. print ("Cool! 4 matches on try", costs)
  125. ...
  126. if set([3,4,5,6]).intersection(found) == set([3,4,5,6]):
  127. print "You Found em all!"
  128. return
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement