A console-based number guessing game built in Python as part of an internship project. The program randomly selects a number, accepts guesses from the user, and provides higher/lower feedback until the correct number is found — with difficulty levels, attempt tracking, and persistent best-score storage.
- Random number generation within a configurable range using Python's
randommodule. - Higher/lower hints after every guess, with input validation.
- Three difficulty levels (Easy, Medium, Hard), each with a different number range.
- Attempt counting to track how many guesses each round took.
- Persistent best scores — the lowest attempt count per difficulty is saved to
best_scores.jsonand remembered across sessions. - Replay loop so the player can play multiple rounds without restarting the program.
number-guessing-game/
├── number_guessing_game.py # Main game logic and entry point
├── tests/
│ └── test_number_guessing_game.py # Unit tests (pytest)
├── requirements.txt # Dev dependency (pytest)
├── .gitignore
└── README.md
- Python 3.8 or later installed (download here)
python number_guessing_game.pyFollow the on-screen prompts to choose a difficulty and start guessing.
Install the test dependency and run the suite with pytest:
pip install -r requirements.txt
pytest| Concept | Where it's used |
|---|---|
random module |
Generating the secret number within the chosen range |
while loops |
Repeating guesses until correct; repeating rounds for replay |
if / elif / else |
Comparing the guess to the secret number |
File I/O (json) |
Persisting best scores between sessions |
| Dataclasses & type hints | Representing difficulty levels and improving code clarity |
- Add a maximum attempt limit per round (lose condition)
- Add a graphical interface (e.g. with
tkinter) - Track average attempts in addition to best attempts
- Add a leaderboard for multiple players
Built by [ADARSH SINGH] as part of an internship project.
This project is open source and available under the MIT License.