I’m working on a personal project and I’m getting user from input that should be and int.
problem is like this:
say I get an input from a user using this code:
guess=int(input('what is your guess?:'))
and the user inserts a letter just to be annoying
I’m gonna be getting a syntax error cause the program can’t change the letter to an integer
but if I do this
guess=input('what is your guess?:')
without the int() command all input I get will be treated as a string and not as an int like I want it to
what do I do now?
import random
number=random.randint(1,10)
guess=int(input('what is your guess?:'))
if guess not in range(1,10) or guess == 0:
print('your guess should be a number between 1 and 10')
while guess is not number:
guess=int(input('guess again:'))
if guess not in range (1,10) or guess == 0:
print('your guess should be a number between 1 and 10')
if guess == number:
print('great job you guessed correctly!')
import random
number=random.randint(1,10)
guess=int(input('what is your guess?:'))
if guess not in range(1,10) or guess ==0 and guess.isnumeric():
print('your guess should be a number between 1 and 10')
while guess is not number:
guess=input('guess again:')
if guess not in range (1,10) or guess == 0:
print('your guess should be a number between 1 and 10')
if guess == number:
print('great job you guessed correctly!')