# Guess the numbers in #python

I was asked by a student for the solution to the guess the numbers game in python, so here it is.

You get 8 guesses to find the secret number.  Each time you guess correctly the game moves to a more complicated level, starting from 1-100, then 1-200, and then the more challenging 1-400 and 1-800.   Good luck on the impossible 1-1600 and beyond levels.

``` # guess the numbers game # by Mr Street # 2015-10-24 import random level = 1 gameOver = False # this is the main loop while not(gameOver):     # get a new random number     target = random.randint(1, 100*(2**(level-1)))     guesses = 0     guessedCorrect = False     #this is each level     while not(guessedCorrect) and guesses < 8:         print("\n\nLEVEL "+str(level))         print("Guess number "+str(guesses+1))         print("I'm thinking of a number between 1 and "+str(100*(2**(level-1)) )+" what is it?")         guess = int(input("? > ")) # my prompt         #check whether it is correct         if guess > target:             print("TOO HIGH!")         elif guess < target:             print("TOO LOW!")         else:             print("CORRECT - YOU ARE A LEGEND!")             guessedCorrect = True # set end of level flag         guesses += 1 # record number of guesses     # you reach this point by either running out of guesses or guessing correctly     if not(guessedCorrect):         print("\nYou have run out of guesses.")     else:         print("\n\nNEXT LEVEL!\n\n")         level += 1 # increase the difficulty ```

#python