Python code question - you are given the grand prize(in USD) and the winning numbers.
Your program will read multiple tickets (6 selected numbers in each ticket) from the input file.
For each ticket, the program calculates its prize won, and outputs the prize (in USD) to the output file.
How to Play the Game?
In each ticket, the player selects five numbers from a set of 69 white balls (numbered 1 to 69)
and one number from 26 red balls (numbered 1 to 26).
The red ball number can be the same as one of the white balls, but a white ball can only be selected once.
The order of selection does not matter.
The numbers in each ticket is not guaranteed to be sorted in any way.
Prize Rule:
The prize rule is given the figure below.
A ‘o means a white ball match and ‘x’ means the red ball match.
ooooox Grand Prize
ooooo $1,000,000
oooox $50,000
oooo $100
ooox $100
ooo $7
oox $7
ox $4
x $4
Input File: The input file is a text file (.txt).
The first line contains only one number which is the grand prize.
The second line contains exactly five numbers, separated by space characters, which are the five winning white balls.
The third line contains only one number which is the winning red ball.
Starting from the fourth line, each line contains exactly six numbers, separated by space characters, which represents a ticket.
The first five numbers are the selected white balls and the last number is the selected red ball.
You cannot assume how many tickets are in the input file.
No matter how many tickets are in the file, your program should read and process all of them.
The output file is a text file (.txt).
The first line contains a single number which is the calculated prize for the first ticket in the input file;
the second line contains a single number which is the calculated prize for the second ticket in the input file; and so on.
Since the prizes are represented in USD, you need to add a '$' before each number.
You can assume that the input file is error-free.
You do not need to consider how to deal with invalid inputs.
The input file is guaranteed to have no empty lines.
Code
def main():
winnigNumbers=[]
ticketNumbers=[]
# Open the file with read only permit
f = open('input.txt')
fw = open("output.txt", "w")
# use readline() to read the first line
grandPrice = f.readline().rstrip('\n\r')
lineNum=f.readline().split()
for num in lineNum:
winnigNumbers.append(int(num.rstrip('\n\r')))
winnigNumbers.append(int(f.readline().rstrip('\n\r')))
line= f.readline()
while line:
ticketNumbers=[]
lineNum=line.split()
countWhileMatchBall=0
for num in lineNum:
ticketNumbers.append(int(num.rstrip('\n\r')))
for i in range(len(ticketNumbers)-1):
for j in range(len(winnigNumbers)-1):
if(ticketNumbers[i]==winnigNumbers[j]):
countWhileMatchBall+=1
break
if(countWhileMatchBall==5 and
ticketNumbers[5]==winnigNumbers[5]):
winningPrice=grandPrice
elif(countWhileMatchBall==5):
winningPrice="$1,000,000"
elif(countWhileMatchBall==4 and
ticketNumbers[5]==winnigNumbers[5]):
winningPrice="$50,000"
elif(countWhileMatchBall==4):
winningPrice="$100"
elif(countWhileMatchBall==3 and
ticketNumbers[5]==winnigNumbers[5]):
winningPrice="$100"
elif(countWhileMatchBall==3):
winningPrice="$7"
elif(countWhileMatchBall==2 and
ticketNumbers[5]==winnigNumbers[5]):
winningPrice="$7"
elif(countWhileMatchBall==1 and
ticketNumbers[5]==winnigNumbers[5]):
winningPrice="$4"
elif(ticketNumbers[5]==winnigNumbers[5]):
winningPrice="$4"
else:
winningPrice="$0"
fw.write(winningPrice+"\n")
line = f.readline()
f.close()
fw.close()
main()
input.txt file
output.txt
code snaps
If you have any query regarding the code please ask me in the comment i am here for help you. Please do not direct thumbs down just ask if you have any query. And if you like my work then please appreciates with up vote. Thank You.
Python code question - you are given the grand prize(in USD) and the winning numbers. Your...
The Powerball is played by selecting five numbers (without repetition) from the white balls labeled 1 through 69 (the order doesn't matter) and one red ball (the powerball) with label from 1 through 26. You win the grand prize if you get all five white numbers plus the powerball. 3. (a.) How many possible tickets are there? What is the probability of winning the grand prize? (b.) You win $4 if you get the powerball and at most one white...
Bonus Question The Powerball multi-state lottery is played by picking 5 numbers between 1 and 59 (the white balls) and an additional bonus number between 1 and 39 (the red Powerball). Twice a week 5 white balls and a red Powerball are drawn from two separate drums revealing the winning numbers. To win at Powerball, your numbers must match the numbers on the winning balls in any of the following nine ways: 5 white balls + red Powerball (Grand Prize)...
Overall odds of winning a prize in mega-millions is approximately 1/15, and the numbers in each ticket is independent of the others. Richard bought two mega-million tickets, his probability of winning the first OR the second ticket is: a. 0.0667 b. 0.1333 c. 0.1289
The Powerball lottery is played twice each week in 44 states, the District of Columbia, and the Virgin Islands. To play Powerball, a participant must purchase a $2 ticket, select five numbers from the digits 1 through 69, and then select a Powerball number from the digits 1 through 26. To determine the winning numbers for each game, lottery officials draw 5 white balls out a drum of 69 white balls numbered 1 through 69 and 1 red ball out...
Write a C++ program that simulates playing the Powerball game. The program will generate random numbers to simulate the lottery terminal generated numbers for white balls and red Powerball. The user will have the option to self-pick the numbers for the balls or let the computer randomly generate them. Set the Grand Prize to $1,000,000,000.00 in the program. Project Specifications Input for this project: Game mode choice – self pick or auto pick Five numbers between 1 and 69 for...
Please post screenshots only File Tools View CMSC 140 Common Projects Spring 2019(1) E - 3 x Project Description The Powerball game consists of 5 white balls and a red Powerball. The white balls represent a number in the range of 1 to 69. The red Powerball represents a number in the range of 1 to 26. To play the game, you need to pick a number for each ball in the range mentioned earlier. The prize of winning the...
PLEASE HELP WITH 2 AND 3!! THANK YOU:) 2. How many 4-digit numbers can be formed from the digits 2,3,4,5,6,7,8 if: i) Each digit may be used only once in each number? ii) Each digit may be used repeatedly in each number? 3. A bag contains five red balls numbered 1,2,3,4,5 and nine green balls numbered 6,7,8,9,10,11,12,13,14. If a ball is drawn at random what is the probability that: i) The ball is red and odd-numbered. ii) The ball is...
This question relates to pseudo random number generators. You will write a c program that pulls the Powerball numbers. You will demonstrate how a deterministic number generator works. In Powerball there are 5 white numbered balls that are pulled out of a drum containing 69 balls numbered 1-69. You cannot pull the same number twice. Additionally one red ball is numbered 1 to 26. You don’t have to worry about the PowerPlay option. A) Write a c program that simulates...
3. An urn contains five white balls numbered from 1 to 5, five red balls numbered from 1 to 5 and five blue balls numbered from 1 to 5. For each of the following questions, please give your answer first in the form that reflects your counting process, and then simplify that to a number. You must include the recipes. No other explanation needed. (a) In how many ways can we choose 4 balls from the urn? (b) in how...
A. Overall odds of winning a prize in mega-millions is approximately 1/15, and the numbers in each ticket is independent of the others. Richard bought two mega-million tickets, his probability of winning the first OR the second ticket is: 0.0667 0.1333 0.1289 B. The data indicate that 10.5% of people with a Cardiovascular Disease who were diagnosed with COVID-19 died. The data also indicate that this percentage for Diabetes is 7.3%, for Chronic Respiratory Disease is 6.3%, Hypertension is 6%,...