I have a problem with my code.
My code is a beginner number guesser. The code is supposed to write an error when the user types a letter when.
I first thought to convert usrin_guess
to an integer and then say "is it a string or integer" but I realized that couldn't work. Then I wrote this... In my head should it work but it makes a failure at if int(usrin_guess) > uo_rand_num:
when I write a letter.
def rand_num(num):
return random.randint(1, num) # Making a random number between the amount of number input and 1
uo_rand_num = rand_num(amount_of_numbers)
while int(usrin_guess) != uo_rand_num:
usrin_guess = input("Enter a number between " + "1" + " and " + usrin_amount_of_numbers + " ")
try:
val = int(usrin_guess)
except ValueError:
val_input == False
if val_input == True:
if int(usrin_guess) > uo_rand_num:
print("The number is lower than " + usrin_guess)
elif int(usrin_guess) < uo_rand_num:
print("The number is higer than " + usrin_guess)
elif int(usrin_guess) == uo_rand_num:
answer = True
usr_guesses += 1
else:
print("Please don't enter a character")