In: Computer Science
For building a lottery simulator on PYTHON:
Pick 5 numbers from 0-9 which will be the winning numbers. Prompt the user to either have the system generate numbers for them or they can pick themselves. If they want to pick themselves, make sure they can only pick a number 0-9.
Check for a 5 number match IN ORDER (from players randomly selected numbers to winning numbers). "Give" user a $10,000 prize.
Check for a 4 number match in which the 5th number is only off by 1 number (from players randomly selected numbers to winning numbers). "Give" user $275.
Print the total spent, total won, and the users loss.
Allow user to keep playing until they want to quit.
Program:
import random as r
x = True
totalspent = 0
totalwon = 0
print("----LOTTERY SIMULATOR IN PYTHON-----") # print
print(
"The entry fees is $1000\nIf you get all 5 numbers correct then you will get $10000\nIf you got 4 correct then you will get $275") # print
while (x): # loop
totalspent += 1000 # adding 1000 to total spent
result = [] # result list
for i in range(5): # generating lottery number using randint function
result.append(r.randint(0, 9))
k = int(input(
"You have to pick 5 numbers from 0-9\n If you want to pick yourself press 1\nFor system generation press 2: ")) # print
l = [] # user number list
if k == 1:
for i in range(5): # loop
l.append(int(input('Pick a number from (0-9):')))
else:
for i in range(5): # loop
l.append(r.randint(0, 9))
print('The generated numbers are:', l)
k = 0
for i in range(5): # checking user numbers with lottery numbers
if l[i] == result[i]:
k += 1 # incrementing k value
if k == 5:
print('You won $10000') # print
totalwon += 10000 # incrementing total won variable
elif k == 4:
print('You won $275') # print
totalwon += 275 # incrementing total won variable
else:
print('You lost') # print
print('The Lottery number is:', result) # print
y = int(input("Press 1 If you want to play again press 0 to quit: ")) # print
if y == 0:
x = False
print('Total Spent: $', totalspent)
print('Total Won: $', totalwon)
if totalwon>=totalspent:
print('Total Loss: $0')
else:
print('Total Loss: $',totalspent-totalwon)
Program Screenshot:

Output:

Hope you understand...
If you have any doubts comment below...plss dont dislike.....