Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from random import *
- import random
- def draw():
- #return a list of six randomly picked numbers
- numbers=list(range(1,50))
- drawn=[]
- for n in range (6):
- x=randint(0,len(numbers)-1)
- no=numbers.pop(x)
- drawn.append(no)
- return drawn
- a=int(input("What is your first number? (maximum of 49)"))
- b=int(input("What is your second number? (different from 1)"))
- c=int(input("What is your third number? (different from 1,2)"))
- i=int(input("What is your fourth number?(different from 1,2,3)"))
- e=int(input("What is your fith number?(different from 1,2,3,4)"))
- f=int(input("What is your sixth number?(different from 1,2,3,4,5)"))
- def winner():
- ticket=[a,b,c,i,e,f]
- wins=0
- costs=0
- while True:
- costs=costs+1
- d=draw()
- matches=0
- for h in ticket:
- if h in d:
- matches=matches+1
- if matches==3:
- print ("You Matched 3 on try", costs)
- elif matches==4:
- print ("Cool! 4 matches on try", costs)
- elif matches==5:
- print ("Amazing!", costs, "trys for 5 matches!")
- elif matches==6:
- print ("Congratulations! you matched all 6 numbers on try", costs)
- return False
- draw()
- winner()
- from random import randint, sample
- # Ontario Lotto 6/49 prize schedule
- COST = 0.50
- PRIZES = [0, 0, 0, 5., 50., 500., 1000000.]
- def draw():
- return set(sample(range(1, 50), 6))
- def get_ints(prompt):
- while True:
- try:
- return [int(i) for i in input(prompt).split()]
- except ValueError:
- pass
- def pick():
- while True:
- nums = set(get_ints(
- "Please enter 6 numbers in [1..49], ie 3 4 17 22 44 47: "
- ))
- if len(nums) == 6 and 1 <= min(nums) and max(nums) <= 49:
- return nums
- def num_matched(picked):
- return len(picked & draw()) # set intersection
- def report(matches):
- total_cost = COST * sum(matches)
- total_won = sum(m*p for m,p in zip(matches, PRIZES))
- net = total_won - total_cost
- # report on the results:
- print("nYou won:")
- print(
- " nothing {:>8} times -> ${:>12.2f}"
- .format(sum(matches[:3]), 0.)
- )
- for i in range(3, 7):
- print(
- " ${:>12.2f} {:>8} times -> ${:>12.2f}"
- .format(PRIZES[i], matches[i], PRIZES[i] * matches[i])
- )
- print(
- "nYou paid ${:0.2f} to win ${:0.2f}, for a net result of ${:0.2f}."
- .format(total_cost, total_won, net)
- )
- def main():
- # pick a set of numbers
- picked = pick()
- # repeat until we have seen 3, 4, 5, and 6-ball matches
- matches = [0, 0, 0, 0, 0, 0, 0]
- while not all(matches[3:]):
- matches[num_matched(picked)] += 1
- report(matches)
- if __name__=="__main__":
- main()
- Please enter 6 numbers in [1..49], ie 3 4 17 22 44 47: 4 6 9 12 14 19
- You won:
- nothing 10060703 times -> $ 0.00
- $ 5.00 181218 times -> $ 906090.00
- $ 50.00 9888 times -> $ 494400.00
- $ 500.00 189 times -> $ 94500.00
- $ 1000000.00 1 times -> $ 1000000.00
- You paid $5125999.50 to win $2494990.00, for a net result of $-2631009.50.
- ...
- costs=0
- found = []
- while True:
- ...
- if matches==3 and 3 not in found:
- found.append(3)
- print ("You Matched 3 on try", costs)
- elif matches==4 add 4 not in found:
- found.append(4)
- print ("Cool! 4 matches on try", costs)
- ...
- if set([3,4,5,6]).intersection(found) == set([3,4,5,6]):
- print "You Found em all!"
- return
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement