Below is my code for guessing a random number. I had to check the input to make sure it was an integer and within the 1-20 range. Everything is working. It outputs the right response if it is not an integer or is out of range but then it continues through the while loop. I thought the try except would send it back before it continued. What have I done incorrectly here? I cannot figure out the problem. Thank you for any help!
import random
tries = 0
name=(raw_input('Hello! What is your name? '))
number = random.randint(1, 20)
print('Hello, ' + name + ', I am thinking of a number between 1 and 20.')
while tries < 6:
guess = (raw_input('Take a guess.' ))
try:
guess = int(guess)
except ValueError:
print 'You did not enter a valid number, try again.'
tries = tries + 1
if guess<1 or guess>20:
print 'Your guess is not between 1 and 20'
if guess < number:
print 'Your guess is too low.'
if guess > number:
print 'Your guess is too high.'
if guess == number:
break
if guess == number:
print 'Good job, ',name,'! You guessed my number in ',tries,' guesses!'
if guess != number:
print 'Sorry, The number I was thinking of was ',number