# Python Tutorials: a Number Guessing Game

1,347

18

1

## Step 1: The Code

After opening a blank python file, type the following code:

--- = tab

import random
goAgain = True
while goAgain == True:
---gameMode = input("EASY/MEDIUM/HARD ")
---if gameMode in ['easy', 'Easy', 'EASY']:
------chosenNumber = random.randint(1,100)
------print("I'm thinking of a number between 1 and 100")
------guessesTaken = 0
------playerGuess = 'void'
------while playerGuess != chosenNumber:
---------playerGuess = input("Guess a number: ")
---------if playerGuess > chosenNumber:
------------print("Too High")
---------else:
------------print("Too Low")
------print("You Guessed It!")

---if gameMode in ['medium', 'Medium', 'MEDIUM']:
------chosenNumber = random.randint(1,1000)
------print("I'm thinking of a number between 1 and 1000")
------guessesTaken = 0
------playerGuess = 'void'
------while playerGuess != chosenNumber:
---------playerGuess = input("Guess a number: ")
---------if playerGuess > chosenNumber:
------------print("Too High")
---------else:
------------print("Too Low")
------print("You Guessed It!")

---if gameMode in ['hard', 'Hard', 'HARD']:
------chosenNumber = random.randint(1,10000)
------print("I'm thinking of a number between 1 and 10000")
------guessesTaken = 0
------playerGuess = 'void'
------while playerGuess != chosenNumber:
---------playerGuess = input("Guess a number: ")
---------if playerGuess > chosenNumber:
------------print("Too High")
---------else:
------------print("Too Low")
------print("You Guessed It!")

---goAgainPrompt = input("Do you want to go again (Y/N) ")
---if goAgainPrompt in ['y', 'Y', 'Yes', 'YES']:
------goAgain = True
---else:
------goAgain = False

## Recommendations

• ### 3D CAM and CNC Class

1,439 Enrolled

## Discussions

Cool idea! I have a suggestion for you. When asking the user what level of difficulty use this: input('easy,medium,hard').lower( ) // by doing this you will not have to worry about the exact input as it will always revert to lower case.