Guess Number Higher OR Lower Python Game

Want to know how to create a guess number higher or lower python game, then you are at the right place today. In this tutorial, I will show you how to make a higher or lower number python game.
Guess the number higher or lower python game is a game where you have to guess a number between like 1 to 10 or 1 to 20 and If you guessed it in your first attempt then booyah.
If you guessed the number wrong the program will tell you either the number you guessed is higher or lower than the answer, you will have 3 attempts to guess the correct number.
It will be a fun and interesting project. It is like a python number guessing game. I will show you everything on how to do it and provide you with the code of this program.
Guess Number Higher OR Lower Python Game Code
from random import randint
number = randint(1,10)
attempts = 0
print("Choose a random number from 1-10")
while attempts != 3:
guess = int(input("Make your guess: "))
if guess > number:
print("Wrong, the number I guessed is lower than this, try again!")
attempts = attempts + 1
elif guess < number:
print("Wrong, the number I guessed is higher than this, try again!")
attempts = attempts + 1
else:
print("Booyah! You guessed correctly.")
exit()
print(f"The number is {number}")
Above is the python code for higher or lower game. Now to run this program you need to have python installed on your computer, if you don’t have then follow this guide: Install and setup python on your computer.
To run this python program, follow the below steps:
- Create a new folder for this python project.
- Open it in a code editor of your choice.
- Create a python file with an ending .py extension.
- Copy the above code and paste it in your file.
- Open command prompt at program folder location.
- And run this command, python filename.py.
Above are the easy and basic steps you need to follow to run this program and after running it you will be asked to guess a number and if you guessed it in your first shot you win or
If it is wrong, you will be given a clue that the number is higher or lower than your guessed number. You will have 3 attempts to guess the correct number, if not guessed then the game is over below is an example output of this game.
Output
Choose a random number from 1-10
Make your guess: 4
Wrong, the number I guessed is higher than this, try again!
Make your guess: 6
Wrong, the number I guessed is higher than this, try again!
Make your guess: 7
Booyah! You guessed correctly.
Choose a random number from 1-10
Make your guess: 7
Wrong, the number I guessed is higher than this, try again!
Make your guess: 8
Booyah! You guessed correctly.
Choose a random number from 1-10
Make your guess: 4
Wrong, the number I guessed is higher than this, try again!
Make your guess: 5
Booyah! You guessed correctly.
Choose a random number from 1-10
Make your guess: 1
Wrong, the number I guessed is higher than this, try again!
Make your guess: 3
Wrong, the number I guessed is higher than this, try again!
Make your guess: 4
Wrong, the number I guessed is higher than this, try again!
The number is 6
As you can, we have successfully created the higher or lower number guessing game in python. I hope you ran the program successfully.
Summary
This was the guess the number higher or lower python game. I hope you found this tutorial helpful and useful. Do share this article with your friends who might be interested in it.
Here are some more python games & programs for you:
- Create a Fruit ninja game in python with code.
- Create Pacman bird game in python with code.
- Create Bouncing ball game in python with code.
- Create minecraft game in python with code.
- Create battleship game in python with code.
I hope you found what you were looking for from this tutorial and if you want more tutorials like this then do join our Telegram channel for future updates.
Thanks for reading, have a nice day 🙂