Skip to content

PawanChoudhary0607/Python-GK-Quiz

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🧠 Python CLI General Knowledge Quiz

Python License Status Type Dependencies

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.


📌 Project Overview

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)


✨ Features

  • 🎯 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.

🛠️ Tech Stack

Component Technology
Language Python 3 (Standard Library)
Randomization random module
Error Handling try / except (built-in exceptions)
Data Structures Lists, Dictionaries
External Dependencies None

📁 Project Structure

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

⚙️ Installation

Clone the repository:

git clone https://github.com/PawanChoudhary0607/Python-GK-Quiz.git
cd Python-GK-Quiz

No additional packages need to be installed — the project uses only Python's standard library.


▶️ How to Run

python3 main.py

Requires Python 3.6+.


🔄 Program Flow

  1. The main menu is displayed with 5 options.
  2. Start Quiz randomly selects 5 questions and asks them one at a time, validating and scoring each answer as it's submitted.
  3. View Quiz Rules explains how answers are checked.
  4. View Score Summary shows the score of every session played so far in the current run, plus an overall total.
  5. Play Again immediately starts a fresh 5-question session.
  6. Exit ends the program with a farewell message.
  7. Invalid menu input and empty quiz answers are rejected with a clear message, and the user is re-prompted — the program never crashes.

💻 Example Terminal Output

=============================================
       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.)


🖼️ Screenshots

Home Menu Quiz Rules
Home Quiz Rules
Quiz Start Correct Answer
Quiz Start Correct Answer
Wrong Answer Score Summary
Wrong Answer Score Summary
Play Again Invalid Input
Play Again Invalid Input
Exit
Exit

🎓 Learning Outcomes

  • 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 KeyboardInterrupt and EOFError to 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.

🧩 Challenges

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

🚀 Future Improvements

  • Add automated unit tests (e.g. with unittest or pytest).
  • Add type hints throughout main.py for stronger static analysis.
  • Add a GitHub Actions CI workflow to run linting/tests on every push.

👤 Author

Pawan Choudhary B.Tech CSE (AI & ML) Python Programming Intern @ DecodeLabs

GitHub: PawanChoudhary0607


📄 License

This project is licensed under the MIT License.

About

A Python CLI General Knowledge Quiz built using Core Python with input validation, score tracking, randomized questions, and a professional terminal interface.

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages