Answer the question
In order to leave comments, you need to log in
How to restart the cycle at the request of the user?
Guessing game:
import random
import sys
running = True
number = random.randint (1, 5)
print ('Guess the number from 1 to 5 to WIN')
print ('or enter "0" to EXIT\n')
while running:
guess = int(input('Enter a number\n'))
if guess == number:
print ('YOU WIN!!!')
running = False
elif guess > number:
print ('Your number is bigger')
print ('Try again\n')
elif guess == 0:
sys.exit('Closing...')
else:
print ('Your number is less')
print ('Try again\n')
input ('Press ENTER to exit')
print ('Closing...')
Answer the question
In order to leave comments, you need to log in
Look, the coolest and most logical way is to try to create a variable that will contain a boolean value and compose a program so that your program monitors this boolean value and when it changes, your guessing game starts / ends
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question