A menu-driven, terminal-based General Knowledge Quiz built entirely with Core Python — no external libraries, no frameworks, no databases. Five questions are randomly selected each session from a pool covering Geography, Science, Technology, History, and General Awareness, with robust input validation and live score tracking.
This is Project 4 of the DecodeLabs Python Programming Internship, a structured, hands-on program focused on writing clean, well-tested Core Python CLI applications. Each project in the internship series is built with the standard library only, documented to a professional standard, and made portfolio/GitHub-ready.
DecodeLabs Internship Context: Python Programming Internship — CLI Projects Series (Project 4 of the series)
- 🎯 Randomized Question Selection — 5 questions are randomly drawn from a 15-question pool for every quiz session.
- 🌍 Multi-Category Coverage — Geography, Science, Technology, History, and General Awareness.
- 🔡 Case-Insensitive Answer Checking —
'Mars','mars', and'MARS'are all treated as correct. - ✂️ Whitespace Tolerant — Leading/trailing spaces around an answer are stripped before comparison.
- 🚫 Empty Answer Rejection — Blank input is never accepted; the user is re-prompted until a real answer is given.
- ✅ Instant Feedback — Each answer is immediately marked correct or incorrect, with the correct answer shown on a miss.
- 📊 Score Summary — View per-session and overall scores at any time from the main menu.
- 🔁 Play Again — Jump straight into a new quiz session without restarting the program.
- 🛡️ Crash-Proof Input Handling — Gracefully handles
Ctrl+C/Ctrl+D(KeyboardInterrupt/EOFError) and invalid menu choices without ever crashing.
| Component | Technology |
|---|---|
| Language | Python 3 (Standard Library) |
| Randomization | random module |
| Error Handling | try / except (built-in exceptions) |
| Data Structures | Lists, Dictionaries |
| External Dependencies | None |
Python-GK-Quiz/
├── main.py # Application entry point and all program logic
├── README.md # Project documentation (this file)
├── LICENSE # MIT License
├── .gitignore # Files/folders excluded from version control
├── PROJECT_STRUCTURE.md # Repository layout reference
└── screenshots/ # Real terminal screenshots
├── home.png
├── quiz-rules.png
├── quiz-start.png
├── correct-answer.png
├── wrong-answer.png
├── score-summary.png
├── play-again.png
├── invalid-input.png
└── exit.png
Clone the repository:
git clone https://github.com/PawanChoudhary0607/Python-GK-Quiz.git
cd Python-GK-QuizNo additional packages need to be installed — the project uses only Python's standard library.
python3 main.pyRequires Python 3.6+.
- The main menu is displayed with 5 options.
- Start Quiz randomly selects 5 questions and asks them one at a time, validating and scoring each answer as it's submitted.
- View Quiz Rules explains how answers are checked.
- View Score Summary shows the score of every session played so far in the current run, plus an overall total.
- Play Again immediately starts a fresh 5-question session.
- Exit ends the program with a farewell message.
- Invalid menu input and empty quiz answers are rejected with a clear message, and the user is re-prompted — the program never crashes.
=============================================
PYTHON GENERAL KNOWLEDGE QUIZ
=============================================
1. Start Quiz
2. View Quiz Rules
3. View Score Summary
4. Play Again
5. Exit
=============================================
Enter your choice (1-5): 1
Starting a new quiz. Good luck!
Question 1 of 5 [Technology]
What does 'CPU' stand for?
Your answer: Central Processing Unit
Correct!
Question 2 of 5 [Technology]
What does 'HTML' stand for?
Your answer: web pages
Incorrect. The correct answer is: Hypertext Markup Language
(Captured directly from a real, executed run of main.py.)
| Home Menu | Quiz Rules |
|---|---|
![]() |
![]() |
| Quiz Start | Correct Answer |
|---|---|
![]() |
![]() |
| Wrong Answer | Score Summary |
|---|---|
![]() |
![]() |
| Play Again | Invalid Input |
|---|---|
![]() |
![]() |
| Exit |
|---|
![]() |
- Designing a menu-driven CLI loop with clean, modular functions.
- Implementing robust input validation (
.strip(),.lower(), empty input rejection) without relying on external packages. - Using
random.sample()to select a fair, non-repeating subset of questions per session. - Handling
KeyboardInterruptandEOFErrorto keep a CLI tool from ever crashing on unexpected input. - Structuring quiz data as a list of dictionaries for simple, readable lookups.
- Writing PEP8-compliant Python and verifying it with
pycodestyle.
- Fair answer comparison — Balancing strict correctness checking with real-world leniency (case and whitespace differences) required normalizing both sides of the comparison consistently.
- Never letting the app crash — Making sure every input path, including keyboard interrupts and empty submissions, is handled gracefully instead of raising an unhandled exception.
- Keeping it simple — Resisting the urge to add databases, files, or classes and instead solving the problem cleanly with core language features only, as required by the internship scope.
- Add automated unit tests (e.g. with
unittestorpytest). - Add type hints throughout
main.pyfor stronger static analysis. - Add a GitHub Actions CI workflow to run linting/tests on every push.
Pawan Choudhary B.Tech CSE (AI & ML) Python Programming Intern @ DecodeLabs
GitHub: PawanChoudhary0607
This project is licensed under the MIT License.








