In: Computer Science
(PYTHON) Lottery program. The program randomly generates a two-digit number, prompts the user to enter a single two- digit number, and determines whether the user wins according to the following rules. Write a loop to let the user play as many times as the user wanted. Use a sentinel or flag to quit out of the loop.
1.if the user’s input matches the lottery In the exact order, the award is $10,000.
2.if all the digits in the user’s input match all the digits in the lottery number, the award is $3,000.
3. if one digit in the user’s input matches a digit in the lottery number, the award is $1,000.
CODE
import random
cont = 'y'
while cont == 'y' or cont == 'Y':
lottery = random.randint(10, 99)
user_input = int(input("Enter your 2-digit lottery number: "))
guess = [user_input // 10, user_input % 10]
computer = [lottery // 10, lottery % 10]
if guess[0] == computer[0] and guess[1] == computer[1]:
print("Congratulations, you have won $10000")
elif guess[0] in computer and guess[1] in computer:
print("Congratulations, you have won $3000")
elif guess[0] in computer or guess[1] in computer:
print("Congratulations, you have won $1000")
else:
print("Sorry, you have not won anything!!")
cont = input("Do you wish to continue? (y/n): ")