137k views
15 votes
Write a lottery program that will ask the user if they would like to pick 5 numbers (1-30) or if they would like to choose EZ Pick where the computer randomly picks their 5 numbers at a cost of $1.00. Then you will give them a chance to also play the Next Chance drawing for an extra $1.00. They do not choose additional numbers for the Next Chance drawing. Once they have all of their selections complete, have the computer game generate the five random winning numbers and if they opted for the Next Chance drawing, select 4 more random numbers. Display all of the users numbers, all of the winning numbers, and display how much, if any, that the player has won based on the following information:

1 Answer

4 votes

Answer:

Step-by-step explanation:

The following code is written in Python and creates arrays for the user's numbers and the next chance numbers, it also creates a cost variable and a did_you_win variable. The function takes in the winning numbers as an array parameter. It asks all the necessary questions to generate data for all the variables and then compares the user's numbers to the winning numbers in order to detect if the user has won. Finally, it prints all the necessary information.

import random

def lottery(winning_numbers):

user_numbers = []

next_chance_drawing = []

cost = 0

did_you_win = "No"

#print("Would you like to choose your own 5 numbers? Y or N")

answer = input("Would you like to choose your own 5 numbers? Y or N: ")

if answer.capitalize() == "Y":

for x in range(5):

user_numbers.append(input("Enter number " + str(x+1) + ": "))

else:

for x in range(5):

user_numbers.append(random.randint(0,31))

cost += 1

next_chance = input("Would you like to enter a Next Chance drawing for $1.00? Y or N: ")

if next_chance.capitalize() == "Y":

for x in range(4):

next_chance_drawing.append(random.randint(0, 31))

cost += 1

if user_numbers == winning_numbers or next_chance_drawing == winning_numbers:

did_you_win = "Yes"

print("User Numbers: " + str(user_numbers))

print("Next Chance Numbers: " + str(next_chance_drawing))

print("Cost: $" + str(cost))

print("Did you win: " + did_you_win)

User Marysue
by
3.7k points