A fun and interactive number guessing game built in Python.
Guess the number, beat the clock, and compete for the top spot on the scoreboard!
Python Number Guessing Game is a console-based game where players attempt to guess a randomly generated number between 0 and 1000. It includes a real-time timer, leaderboard system, and data persistence using JSON files.
Your task? Guess the number as fast as possible and see your name rise to the top of the leaderboard.
- Enter your name to start the game.
- The computer secretly picks a random number between 0 and 1000.
- Keep guessing until you find the number — hints like
Go Higher!orGo Lower!guide you. - Your total time to find the number is recorded and added to the leaderboard.
- Compete with yourself or others to get the fastest time!
- 💡 Randomized number generation every playthrough
- ⏱️ Real-time timer to measure your guessing speed
- 🏆 Leaderboard system saved to
score_board.json - 🧹 Reset scores with one menu option
- 💬 Menu-driven interface for easy navigation
- 📂 Automatic data saving using JSON files
- 🧠 Digit-only input validation prevents errors during gameplay
Number-Guessing-Game/ │ ├── main.py # Main game file ├── README.md # Project documentation └── LICENCE # (MIT Licence)
- Ensure you have Python 3 installed on your system.
- Download or clone this repository:
git clone https://github.com/Sheikh-H/Number-Guessing-Game.git- Navigate into the folder:
cd Number-Guessing-Game- Run the game:
python main.pyFollow the instructions and see how quickly you can find the number!
- Random Number: Generated between
0and1000usingrandint(). - Timer: Starts when you begin guessing and stops when you find the correct number.
- Leaderboard: Each player's time is stored in a JSON file and displayed in sorted order.
- Reset: You can clear all scores at any time via the main menu.
- Cross-platform: Works on both Windows and macOS/Linux (auto-detects
clsorclear).
| Library | Purpose |
|---|---|
random |
Generates the random number for guessing |
time |
Controls timers and countdowns |
os |
Clears the console screen dynamically |
sys |
Manages text and output control |
json |
Saves and loads player scores persistently |
Scores are stored inside score_board.json as a simple JSON structure:
{
"scores": [
{"player": "SHEIKH", "time": "01:23"},
{"player": "ALICE", "time": "02:15"}
]
}
The leaderboard automatically sorts players by the fastest completion time.
*WELCOME TO THE PYTHON NUMBER GUESSING GAME* 1. Start Game 2. View Scoreboard 3. Reset Scores 4. Exit Game What would you like to do? > 1 Taking you to the game now... We need to put your results on the scoreboard. What is your name? > Sheikh Great 'SHEIKH'! Let's get you started... The script has thought of a number between 0 and 1000. Enter your guess: > 500 Go higher! > 750 Go lower! > 650 Go higher! > 670 You found the number! SHEIKH! You finished in 01:23
- 🎨 Add color-coded output for hints and results
- 📈 Introduce difficulty levels (Easy / Medium / Hard)
- 🧾 Add a score history view with timestamps
- 💾 Store high scores in a database for multiplayer mode
This project is licenced under the MIT Licence — see the LICENCE file for details.
MIT Licence Copyright (c) 2025 Sheikh Hussain Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.