# imports the random module so we can use a function that will give a random number import random # A variable that will count how many guesses we've taking guessesTaken = 0 # Put a random number between 1 and 20 into the variable named number number = random.randint(1, 20) # Text to print out print'I am thinking of a number between 1 and 20.' # A loop that will keep running as long as we've guessed less than six times while guessesTaken < 6: # Text to print print'Take a guess.' # Assign whatever the user types to the variable guess guess = input() # Turn whatever the user types into an integer guess = int(guess) # Increase our count of the number of guesses taken guessesTaken = guessesTaken + 1 # Figure out what to print by checking if our guess is too high or too low if guess < number: print'Nope, too low.' if guess > number: print'Nope, too high.' # If we guess the correct number break out of the loop if guess == number: break # This is the end of our while loop # If we guessed the correct number, tell the user if guess == number: # Turn the number of guesses into a string guessesTaken = str(guessesTaken) print'Good job! You guessed my number in', guessesTaken, 'guesses!' # If we guessed over six times and didn't get the number, tell the user # what the number was if guess != number: number = str(number) print'Nope. The number I was thinking of was ',number