import random number = random.randint(1, 100) attempts = 0 # count no of attempts to guess the number guess = 0 while guess != number: guess = eval(raw_input('Guess a number: ')) attempts += 1 if guess == number: print 'Correct! You used', attempts, 'attempts!' break elif guess < number: print 'Go higher!' else: print 'Go lower!'