Ever wondered how to combine simple game logic with real-world data persistence? In this post, we’ll walk through how I created a Python-based Number Guessing Game that uses an SQLite database to track player points and maintain a leaderboard.
🔍 Project Overview
The project is a CLI (Command Line Interface) number guessing game where:
- Players choose a difficulty level.
- They have 5 attempts to guess the correct number.
- Points are awarded based on how quickly they guess the number.
- The game stores user points in an SQLite database.
- It includes a leaderboard to showcase top players.
🛠️ Core Features
1. Difficulty Selection
Players can choose from:
- Easy: 1–10
- Medium: 1–100
- Hard: 1–1000
This helps cater to different player skill levels.
2. Random Number Generation
Using Python’s random module, the program generates a number within the difficulty range. Players get 5 attempts to guess correctly.
3. Point System
Points awarded are based on the number of guesses left:
- 3 guesses left → 10 points
- 2 guesses left → 5 points
- Otherwise → 2 points
This adds a strategic element — the faster you guess, the more you score.
4. User Authentication
Each user is identified by a username and a secret word. This helps:
- Prevent impersonation.
- Securely update scores.
New users are prompted to create a secret word. Returning users must verify theirs to update their points.
5. SQLite Leaderboard
Data is stored in a lightweight SQLite database:
users (
username TEXT PRIMARY KEY,
points INTEGER,
secret_word TEXT
)
After each round, the game displays a live leaderboard, sorted by the highest points.
💡 Why This Project Matters
This simple game is more than just entertainment — it’s an entry point to essential programming concepts:
- Input handling
- Conditional logic
- Loops
- Error handling
- Database integration
- Data validation
🔗 How to Run the Project
Clone the repo:
git clone https://github.com/mobile-desk/2025-Python-Projects.git
cd 2025-Python-Projects/guessing
python number_guessing.py
🚀 What’s Next?
Here are a few ideas to take this further:
- Add levels or rounds to extend gameplay.
- Implement a web version with Flask or Django.
- Add session history or game statistics per user.
- Hash the secret word using
hashlibfor better security.
🧠 Final Thoughts
This project is a fun and practical way to learn Python and databases. It’s beginner-friendly but also scalable if you’re looking to build on it. Whether you’re teaching Python or learning yourself, this guessing game offers a real sense of progress and accomplishment.




Leave a reply to Getting Started with Python: Install and Run Your First Program – TechInnovom Cancel reply