Question
THIS IS IN PYTHON BASE CODE::: THIS IS PYTHON maxGuesses should be only 10 --- from random import randint # imports the randint function from
THIS IS IN PYTHON
BASE CODE:::
THIS IS PYTHON maxGuesses should be only 10
---
from random import randint # imports the randint function from the random class
numGuesses = 6 # The range of numbers to guess = 2^numGuesses upper_number = 60 # initiates the upper bound of numbers to guess lower_number = 1 # initiates the lower bound ticket = 10 # Assigns the number to be guess guess = randint(lower_number, upper_number) # makes as initial random guess for count in range(numGuesses): # iterates through each number in the list of loterry numbers if guess == ticket: print("You got it!") print("The number of tries were:",count) break elif guess > ticket: upper_number = guess guess = randint(lower_number, upper_number) elif guess = numGuesses: # if we reach the max number of tries then quit print("Sorry, you ran out of tries!") print("The number of tries were:",count)
1. Generate 5 random numbers integer (whole) and store them in 5 separate variables. 2. Display some instructions to user, on what is expected - i.e. This is a digital lottery for 5 numbers ranging from 1 to 99. You have a chance to win it is you guess all 5 numbers correctly. 3. Store loop number, i.e. you will need to know if that was 1st loop or 2nd.. etc. 5th. 4. Start most outer loop. Check what loop number is running. Use SWITCH CASE control to assign maxGuesses variable a corresponding value from those you generated in the step 1 5. Start the INNER LOOP same as given in the BASE CODE, but limit it to 10 attempts. 6. If user guessed the number correctly during the INNER LOOP execution - REMEMBER the WINNING NUMBER, then move to NEXT OUTER LOOP CYCLE 7. IF user exhausted all 10 attempts and did not guess the number correctly - REMEMBER the ZERO, then move to NEXT OUTER LOOP CYCLE. 8. When all cycles completed - you should have your WINNING numbers verified and ready to print. How to proceed: 1. Make sure the Base Code (as offered in this exercise) is running without errors. 2. Consider Nested loops examples discussed in suggested URLs listed above. 3. Consider pseudocode tips offered - implement nested loops to check 5 numbers ( from 1 to 99) of the lottery ticket, generated randomly and giving a user 10 attempts per each of 5 numbers. 4. Test your solutionStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started