Skip to content

Beginner-friendly Python number guessing game that practices loops, conditionals, and user input handling.

License

Notifications You must be signed in to change notification settings

Sheikh-H/Number-Guessing-Game

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 

Repository files navigation

🎯 Python Number Guessing Game

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!


📘 Overview

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.


🎮 Gameplay Flow

  1. Enter your name to start the game.
  2. The computer secretly picks a random number between 0 and 1000.
  3. Keep guessing until you find the number — hints like Go Higher! or Go Lower! guide you.
  4. Your total time to find the number is recorded and added to the leaderboard.
  5. Compete with yourself or others to get the fastest time!

🧩 Features

  • 💡 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

📂 Folder Structure

Number-Guessing-Game/
│
├── main.py                     # Main game file
├── README.md                   # Project documentation
└── LICENCE                     # (MIT Licence)

⚙️ How to Run the Game

  1. Ensure you have Python 3 installed on your system.
  2. Download or clone this repository:
git clone https://github.com/Sheikh-H/Number-Guessing-Game.git
  1. Navigate into the folder:
cd Number-Guessing-Game
  1. Run the game:
python main.py

Follow the instructions and see how quickly you can find the number!


🧠 How It Works

  • Random Number: Generated between 0 and 1000 using randint().
  • 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 cls or clear).

💻 Technologies Used

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

📊 Leaderboard System

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.


🏁 Example Gameplay

*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

🚀 Future Improvements

  • 🎨 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

📄 Licence

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.

Footnote

🗣️ Feel free to follow, connect, and chat!

GitHub LinkedIn Gmail Portfolio

About

Beginner-friendly Python number guessing game that practices loops, conditionals, and user input handling.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages