Answer:
The complete program is:
import random
keepGoing = True
num = random.randint(0,9)
guess = int(input("Your guess: "))
while keepGoing == True:
if num == guess:
print("You were correct!")
keepGoing = False
else:
print("You were wrong.")
guess = int(input("Your guess: "))
keepGoing = True
Step-by-step explanation:
To answer this program, I let the computer generate a random number, then let the user make a guess.
This imports the random module
import random
This initializes a Boolean variable keepGoing to True
keepGoing = True
Generate a random number
num = random.randint(0,9)
Let the user take a guess
guess = int(input("Your guess: "))
The loop is repeated until the user guesses right
while keepGoing == True:
Compare user input to the random number
if num == guess:
If they are the same, then the user guessed right
print("You were correct!")
Update keepGoing to False
keepGoing = False
If otherwise,
else:
then the user guessed wrong
print("You were wrong.")
Prompt the user for another number
guess = int(input("Your guess: "))
Update keepGoing to True
keepGoing = True