Struggling to get ValueError to work in python 3 guessing game
I have followed a tutorial to create a guessing game in python 3 and i thought i could make it better so i created a timed intro with error inputs recognition and it all seemed to be going well. However, when i came time to ensure when a player inputted anything other than a number(IE exception handling) it just fails out. The game it self functions just not the non integer in the guessgame I have tried the following with ValueError if, else try, except if guess == ValueError All to no avail, anyway, code is below and in my code area. Any help to solve this would be much appreciated. import time def guessgame(): import random # brings in random generator number = random.randint(1, 20) # assigns random value between 1, 20 numofguesses = 0 # sets number of guesses to 0 print("Hello what is your name?") name = input() print("The number i am thinking of is between 1 and 20", name) # user defined name for numofguesses in range(6):# if number of guesses left is less that 6 do the following print("Take a guess") guess = input() # assign guess variable to user input guess = int(guess) # ensures guess is an number if guess < number: print("Number is too low!") if guess > number: print("Number is too high!") if guess == number: break else: if ValueError: #THIS IS THE JERK THAT WONT WORK print("Please enter a number") if guess == number: numofguesses = str(numofguesses) print("Well done", name, "You guessed the number in: ", numofguesses) gameiniate() if guess != number: number = str(number) print(" Wrong! unlucky, the number was: ", number) def gameiniate(): print("Would you like to play a game? Yes or No") game = input().lower() yeschoice = ("yes", "y") nochoice = ("no", "n")