In the below script I like to add if someone guess number less than 0 or more than 20 then it should give message and terminate the program. How I can do that? thanks
import random
n = random.randint(1, 20)
guess = int(input("Enter an integer from 1 to 20: "))
while n != "guess":
print
if guess < n:
print ("guess is low")
guess = int(input("Enter an integer from 1 to 20: "))
elif guess > n:
print ("guess is high")
guess = int(input("Enter an integer from 1 to 20: "))
else:
print ("you guessed it!")
break
print
Python
Last Comment
snhandle
8/22/2022 - Mon
gelonida
the command you're looking for is `break`, which breaks out of a while or for loop.
the command you're looking for is `break`, which breaks out of a while or for loop.
Open in new window