Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Number Guessing Game

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.

Features

  • Random number generation within a configurable range using Python's random module.
  • 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.json and remembered across sessions.
  • Replay loop so the player can play multiple rounds without restarting the program.

Project Structure

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

Getting Started

Prerequisites

Running the Game

python number_guessing_game.py

Follow the on-screen prompts to choose a difficulty and start guessing.

Running the Tests

Install the test dependency and run the suite with pytest:

pip install -r requirements.txt
pytest

How It Works

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

Possible Future Improvements

  • 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

Author

Built by [ADARSH SINGH] as part of an internship project.

License

This project is open source and available under the MIT License.

About

Python number guessing game with difficulty levels, score tracking, and unit tests.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages