Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

A simple lottery game in python If someone has $10 and plans to purchase some lottery tickets. Each lottery ticket costs $2, and the winning

A simple lottery game in python

If someone has $10 and plans to purchase some lottery tickets. Each lottery ticket costs $2, and the winning prize is random from $0 - 10. gain = random.randint(0, 10) can be used to generate a random int and store it in a variable "gain". First, ask the user to input the number of lottery tickets he wants to buy. If the user inputs any negative or decimal number or positive integer numbers that make the cost of buying lottery tickets exceeding the budget, the program will return to ask the user how many lottery tickets he wants to buy until the user inputs a valid number. Next, the program will first subtract the cost of buying those numbers of lottery tickets from the budget and generate an output of the winning prize for each ticket. Then, the amount of winning prize will be added to user's budget. In the end, provide the user a chance to input whether or not he wants to play the lottery game again. If he inputs "Y", every ticket he bought and gained prize will be cleared and he will receive a brand new $10 and return to the question asking how many lottery tickets he wants to buy again. If he inputs anything else, the program will exit.

Here is an example output:

Money Available: 10 dollar(s)

How many lottery tickets do you want to buy?

5

The user wants to buy 5 lottery ticket(s)

This will cost 10 dollar(s), your remaining money is 0 dollar(s)

Lottery ticket 1 : You earned 2 dollar(s) Lottery ticket 2 : You earned 9 dollar(s) Lottery ticket 3 : You earned 5 dollar(s)

Lottery ticket 4 : You earned 2 dollar(s) Lottery ticket 5 : You earned 7 dollar(s)

You earned a total of 26 dollar(s) in the lottery

Money available: 26 dollar(s)

Want to play again?(Y?N)

N

Good Bye!

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions