Question

In: Computer Science

For building a lottery simulator on PYTHON: Pick 5 numbers from 0-9 which will be the...

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.

Solutions

Expert Solution

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.....


Related Solutions

In a lottery, each ticket has 5 one-digit numbers 0-9 on it. (with no digit repeating...
In a lottery, each ticket has 5 one-digit numbers 0-9 on it. (with no digit repeating twice) You win only if your ticket has the digits in the required order. What are your chances of winning?
One of the games of the Massachusetts Lottery is the daily numbers.  Four digits (0 - 9)...
One of the games of the Massachusetts Lottery is the daily numbers.  Four digits (0 - 9) are drawn at random thus producing a 4 digit number. Your friend has the following theories about the digits drawn: #1. Over the year the average of the total of the 4 digits drawn each day is 24 #2. If the first digit of the 4 digits drawn is even the last digit is odd at least 75% of the time #3. The middle...
In the Mega Million Lottery, you pick five numbers from 1 – 75 AND one number...
In the Mega Million Lottery, you pick five numbers from 1 – 75 AND one number from 1 – 15. What is the probability you match ALL the numbers?
Suppose you play a "daily number" lottery game in which three digits from 0–9 are selected...
Suppose you play a "daily number" lottery game in which three digits from 0–9 are selected at random, so your probability of winning is 1/1000. Also suppose lottery results are independent from day to day. A. If you play every day for a 7-day week, what is the probability that you lose every day? B. If you play every day for a 7-day week, what is the probability that you win at least once? (Hint: Make use of your answer...
Lottery One state lottery game has contestants select 5 different numbers from 1 to 45. The...
Lottery One state lottery game has contestants select 5 different numbers from 1 to 45. The prize if all numbers are matched is 2 million dollars.   The tickets are $2 each. 1)    How many different ticket possibilities are there? 2)    If a person purchases one ticket, what is the probability of winning? What is the probability of losing? 3)    Occasionally, you will hear of a group of people going in together to purchase a large amount of tickets. Suppose a...
Consider the set of integer numbers from 0 to 9, that is {0, 1, 2, 3,...
Consider the set of integer numbers from 0 to 9, that is {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}. Bob wishes to use these numbers to create a 7-digit password to secure his new laptop. Note that each number can appear in any position (for example, 0 can be the first number in the password). (a) Find the number of 7-digit passwords that are possible. (b) Find the number of 7-digit passwords with distinct digits. (c) Find...
Create a JAVA lottery game application.  Generate four random numbers, each between 0 and 9 (inclusive).  Allow the...
Create a JAVA lottery game application.  Generate four random numbers, each between 0 and 9 (inclusive).  Allow the user to guess four numbers.  Compare each of the user’s guesses to the four random numbers and display a message that includes the user’s guess, the randomly determined four-digit number, and the amount of points the user has won as follows: No matches 0 points Any one digit matching 5 points Any two digits matching 100 points Any three digits matching 2,000 points All four...
A lottery is conducted in which 7 winning numbers are randomly selected from a total of...
A lottery is conducted in which 7 winning numbers are randomly selected from a total of 62 numbers (1-62). In addition, the Powerball, a single winning number, is selected from an independent pool of 26 numbers (1-26). You select 7 numbers from the pool of 62 numbers. What is the probability that you will select at least one of the winning numbers?
A lottery is conducted in which 7 winning numbers are randomly selected from a total of...
A lottery is conducted in which 7 winning numbers are randomly selected from a total of 62 numbers (1-62). In addition, the Powerball, a single winning number, is selected from an independent pool of 26 numbers (1-26). You select 7 numbers from the pool of 62 numbers. If the probability of choosing 2 of the 7 winning numbers from the pool of 62 numbers is .08862, what is the probability will choose the Powerball from the pool of 26 numbers?
In one type of lottery 5 distinct numbers are picked at once from 1, ..., 40...
In one type of lottery 5 distinct numbers are picked at once from 1, ..., 40 uniformly at random. a. Describe the sample space and P to model this experiment. b. What is the probability that out of the 5 picked numbers exactly 3 will be even?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT