Guest User

Untitled

a guest
Oct 24th, 2018
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. #!/usr/bin/python3
  2. import random
  3.  
  4.  
  5. def GetTime(draws):
  6. # Just a helper function for printing how much time has passed to win the jackpot.
  7. years = draws // 104
  8. rem = draws % 104
  9. weeks = rem // 2
  10. return "{} years and {} weeks".format(years, weeks)
  11.  
  12. # Automatically generates lottery numbers, since there's an equal chance of hitting any particular set,
  13. # selecting your own numbers is irrelevant.
  14. # Gets a unique set of 5 numbers from 1-70
  15. my_numbers = set(random.sample(range(1, 71), 5))
  16.  
  17. # Set your Mega-Ball (1 - 25) *NOT unique, can be a duplicate number from my_numbers
  18. mega_ball = random.randint(1, 25)
  19.  
  20. print("Your Quick-Pick lottery numbers: {} + MB: {}".format(my_numbers, mega_ball))
  21. print("Calculating time to win, this could take a while...")
  22.  
  23. drawings = 0
  24.  
  25. while True:
  26. drawings += 1
  27. # Checking for mega_ball first, since we avoid a lot of unnecessary comparisons if it doesn't match.
  28. if (random.randint(1, 25) == mega_ball and my_numbers == set(random.sample(range(1, 71), 5))):
  29. break
  30.  
  31. # WINNER!
  32. print("You won! Drawing number {} is your lucky break!".format(drawings))
  33. print("Your numbers hit the jackpot after playing the lottery for {}".format(GetTime(drawings)))
  34. print("You spent ${} on lottery tickets.".format(drawings * 2))
Add Comment
Please, Sign In to add comment