Loading Page Content...
Preparing courses, live labs, and learning resources.सामग्री लोड हो रही है, कृपया प्रतीक्षा करें...
Preparing courses, live labs, and learning resources.सामग्री लोड हो रही है, कृपया प्रतीक्षा करें...
Interactive testing and automated assessment engines are among the most ubiquitous real-world software applications—from university entrance portals to edtech learning platforms.
In this capstone project, you will combine lists, dictionaries, functions, control loops, and file persistence to build an interactive, production-ready CLI Quiz Application equipped with score tracking, conceptual explanations, and a persistent top-score leaderboard.
Imagine the computer system behind India's famous quiz show Kaun Banega Crorepati (KBC):
+-------------------------------------------------------------------------+ | KAUN BANEGA CROREPATI (KBC) QUIZ ENGINE | +-------------------------------------------------------------------------+ | | | 1. Question Bank (RAM/File) ──> Shuffled randomly for each contestant | | | | 2. Computer Screen Display ──> Formats Question + Options (A, B, C, D)| | | | 3. Contestant Input Buffer ──> Validates input: strictly 'A'-'D' or 'Q'| | | | 4. Evaluation Engine ──> "Sahi Jawab!" or "Galat Jawab!" | | ──> Explains why correct & updates score | | | | 5. Leaderboard Storage ──> Appends Name, Score, Accuracy to | | 'leaderboard.txt' via with open(...) | | | +-------------------------------------------------------------------------+
Every question is a structured dictionary, each response is sanitized against invalid inputs, and final scores are preserved on disk so winners are remembered across game sessions.
Our Quiz Application consists of 4 decoupled components:
"A", "B", "C", or "D"), and a brief conceptual explanation.quiz_leaderboard.txt.Here is the modular, fully runnable Quiz Application script:
| Practice | Bad Implementation | Gold-Standard Implementation |
|---|---|---|
| Question Storage | Hardcoding if question == 1: cascades | Structured data structures (list of dictionaries) |
| Input Validation | Assuming input is always valid | Strict while True loop validating 'A' through 'D' |
| Question Order | Presenting static questions in identical order | Shuffle questions with random.sample() for fairness |
| Leaderboard Sync | Overwriting file on every play | Append mode ("a") preserving historic competition data |
| Feedback | Only showing final score at the very end | Immediate question-by-question feedback and insights |
| Score Sorting | Printing entries in raw chronological order | Sort descending by score using entries.sort(key=...) |
random.sample(seq, len(seq)) to create a non-destructive shuffled copy of a sequence..strip().upper() to gracefully accept " a ", "A", or "a".'a'): Ideal for logging events, audit trails, and leaderboard score archives without truncating prior history.list.sort(key=lambda item: item[1], reverse=True) to order multi-column tuples or dictionaries.try...except ValueError to prevent sudden crashes.FileNotFoundError when initializing terminal databases.load_data(), save_data(), display_menu(), add_record()).In TV quiz shows, contestants can trigger a 50-50 Lifeline that removes two incorrect choices, leaving only the correct answer and one randomly chosen wrong answer.
Add a 50-50 Lifeline feature to the Quiz Application:
use_fifty_fifty(question_item):use_fifty_fifty on a sample question and verifying that exactly 2 options remain.In the next lesson, we will continue your Python learning journey with Expense Tracker (16: Projects).
Continue learning with hands-on practice, examples, and exercises in the upcoming topic.
| Previous Lesson | Next Lesson |
|---|---|
| Contact Book | Expense Tracker |
Test your understanding of this lesson with 5 questions. Each question has one correct answer.