Lottery Ticket Challange- Python CodingI have coded...import random#listspick=[]rand_ticket=[]#variables#writeoutFile = open("lotteryTicket.txt","w")count=0ticket=""while count < 3:ticket=(int(input("Enter a 1 digit number:")))ticketList=pick.append(ticket)count=count+1outFile.write(str(ticket)+"\n")outFile.close()#print out the numbers they pickedprint("Your ticket number is %s"%(pick))#read the fileinFile = open("lotteryTicket.txt","r")line = inFile.readline()while (line):line = inFile.readline()count2=0while count2<3:rand_ticket.append(random.randint(1, 9))count2+=1print("The winning ticket is %s"%(rand_ticket))#compare numberscomplete this code to...Compare the text ticket and the random numbers.  If they match number (see below), output the prizeThe numbers can be in any orderthe random numbers can be duplicates, so be careful how you countOne number match - free ticketTwo numbers match  - $2.00Three numbers match - $10.00

Question
Asked Dec 10, 2019
149 views

Lottery Ticket Challange- Python Coding

I have coded...

import random
#lists
pick=[]
rand_ticket=[]
#variables
#write
outFile = open("lotteryTicket.txt","w")
count=0
ticket=""
while count < 3:
ticket=(int(input("Enter a 1 digit number:")))
ticketList=pick.append(ticket)
count=count+1
outFile.write(str(ticket)+"\n")
outFile.close()
#print out the numbers they picked
print("Your ticket number is %s"%(pick))
#read the file
inFile = open("lotteryTicket.txt","r")
line = inFile.readline()
while (line):
line = inFile.readline()
count2=0
while count2<3:
rand_ticket.append(random.randint(1, 9))
count2+=1
print("The winning ticket is %s"%(rand_ticket))
#compare numbers

complete this code to...

  • Compare the text ticket and the random numbers.  If they match number (see below), output the prize
  • The numbers can be in any order
  • the random numbers can be duplicates, so be careful how you count
One number match - free ticket
Two numbers match  - $2.00
Three numbers match - $10.00
check_circle

Expert Answer

Step 1

Programming Instructions:

  • Create a python program and declare the required counter variables ‘count3’ and ‘k’ as 0(zero).
  • Then checks for the same number in the ‘pick’ list from the generated random numbers ‘rand_ticket’ list and if any same number found then swap t...
help_outline

Image Transcriptionclose

import random #lists pick=[] rand_ticket=[) #variables #write out File = open("lotteryTicket.txt","w") count-0 ticket="" while count < 3: ticket=(int(input ("Enter a 1 digit number:"))) ticketlist=pick.append (ticket) count=count+1 out File.write(str(ticket)+"\n") out File.close() #print out the numbers they picked print("Your ticket number is %s"%(pick)) #read the file infile = open("lotteryTicket.txt","r") line = infile.readline() while (line): line = inFile.readline() #initializing counter variables by e count2=0 *SwappiLIIg CveI y LICL cu numIUCI temp - pick[0] pick[0] = pick[j] pick[j] = temp count3 +- 1 k += 1 %3D break; count2 += 1 #Showing results: count3=0 k=0 print ("The winning ticket is %s"%(rand_ticket)) if count3 == 1: while count2<3: print("One number match - free ticket") #generating number randomly from 1 to 9 rand_ticket.append (random.randint(1, 9)) elif count3 == 2: - $2.00") print("Two numbers match for j in range (k, 3): if(rand_ticket[count2] == pick[j): elif count3 == 3: #swapping every checked number with 'pick[0]' position print("Three numbers match - $18.00") temp = pick[e] pick[0] = pick[j] = temp else: print ("try again........") pick[j]

fullscreen

Want to see the full answer?

See Solution

Check out a sample Q&A here.

Want to see this answer and more?

Solutions are written by subject experts who are available 24/7. Questions are typically answered within 1 hour.*

See Solution
*Response times may vary by subject and question.

Related Computer Science Q&A

Find answers to questions asked by student like you
Show more Q&A
add
question_answer

Q: Staying Current with TechnologyHaving accepted a job in the field you're most interested in, you now...

A: Ways to stay current with products/technologies/trendsNo matter what your role is or what field you ...

question_answer

Q: For the following problems assume 1 kilobyte (KB) 1024 kilobytes. 1024 bytes and 1 megabyte (MB) For...

A: a) Bits in offset = log2(page size)Given, every byte in the page have a unique address so we have co...

question_answer

Q: Difference in c and c++ programming languages?

A: Difference between C and C++ programming language:

question_answer

Q: What is a VPN and what technologies are used to create one?

A: Virtual Private Network (VPN) and technologies usedA VPN is a private network that uses public netwo...

question_answer

Q: b. How many bits are required to address a 4M × 16 main memory if main memory is byte-addressable?c....

A: A memory is used to store some data on the computer. The data is stored in memory has a unique addre...

question_answer

Q: Design an Essay class that is derived from the GradedActivity class:class GradedActivity{private:dou...

A: Program:#include &lt;iostream&gt; using namespace std; class GradedActivity{ private: double score; ...

question_answer

Q: Transient PopulationPopulations are affected by the birth and death rate, as well as the number of p...

A: Program:#include &lt;iostream&gt;using namespace std;double population(double P, double B, double D,...

question_answer

Q: using this link to read the background information, https://www.bartleby.com/solution-answer/chapter...

A: SQL query for the “PAYMENT” table on MySQL:CREATE TABLE PAYMENT (PMT_ID INT NOT NULL, PMT_DATE DATE,...

question_answer

Q: Which of the following detects unauthorized user activities, attacks, and network compromises and en...

A: System that detects unauthorized user activities and prevents breaches from occuringIntrusion Detect...