# Plays a lottery game with the user, reading # the user's numbers and printing how many matched. import random NUMBERS = 6 MAX_NUMBER = 40 PRIZE = 100 # Generates a set of the winning lotto numbers, # which is returned as a set. def create_winning_numbers(): winning = set() while len(winning) < NUMBERS: num = random.randint(1, MAX_NUMBER) winning.add(num) return winning # Reads the player's lottery ticket from the console, # which is returned as a set. def read_ticket(): ticket = set() print("Type your", NUMBERS, "lotto numbers: ") while len(ticket) < NUMBERS: num = int(input("next number? ")) ticket.add(num) print() return ticket def main(): # get winning number and ticket sets winning = create_winning_numbers() ticket = read_ticket() # print results print("Your ticket was:", ticket) print("Winning numbers:", winning) # keep only winning numbers from ticket (intersect) matches = ticket.intersect(winning) if len(matches) > 0: prize = 100 * 2 ** len(matches) print("Matched numbers:", matches) print("Your prize is $", prize) main()