Made a guessing game but I think I coded something wrong when checking whether if the input is a number or not. My goal is that the user is only allowed to print 4 numbers(no letters). I think I did a mistake with the isdigit() area. Help plz! Thank you
Error: "invalid literal for int() with base 10: 'f999' "
BTW this is my first post. Not sure if my formatting is correct
Error: "invalid literal for int() with base 10: 'f999' "
BTW this is my first post. Not sure if my formatting is correct
import random n = random.randint(0, 9999) guess = int(input("Enter number from 0 to 9999")) print() while n != "guess": if len(str(guess)) < 4: print ("Invalid! Not enough characters. 4 characters only") guess = int(input("Enter number from 0-9999 ")) print() elif not guess.isdigit(): print("Only numbers!") guess = int(input("Enter number from 0-9999 ")) print() elif len(str(guess)) > 4: print ("Invalid! Too many characters. 4 characters only!") guess = int(input("Enter number from 0-9999 ")) print() elif guess < n: print ("too low") guess = int(input("Enter number from 0-9999 ")) print() elif guess > 9999: print("Invalid") guess = int(input("Enter number from 0-9999 ")) print() elif guess < 0: print("Invalid") guess = int(input("Enter number from 0-9999 ")) print() elif guess > n: print ("too high") guess = int(input("Enter number from 0-9999 ")) print() else: print ("You guessed it!") break print