I wrote the below code for a simple math. As I know it should work perfectly. But I'm getting an error with the string format. The shell showing a message that "NameError: name 'guess' is not defined". But the variable is already defined there though.
import random
import re
#select a random number
myNumber = random.randint(1, 20)
#loop for the game
while True:
try:
guess = int(input("Guess a number and put here : "))
except ValueError:
print("not a number {}".format(guess))
else:
if not guess in range(1, 20):
print('Put only number between 1 - 20')
continue
elif guess == myNumber:
print("that's right")
break
else:
print("Bummer!")
int()will throw an exception instead of returning a value, and thereforeguessis not defined when you try to print its value in theexceptclause.