Python Mini-Projects, Part 2
After this lesson, you will be able to:
- Use pandas (DataFrames, groupby, correlation) to compute and present a multi-section text dashboard
- Design a CLI quiz game with three cooperating classes (Question, Quiz, Leaderboard)
- Apply the decorator pattern to add cross-cutting behavior (timing) without modifying core logic
- Use random.shuffle, json persistence, and OOP encapsulation in a single coherent program
Before You Start
#Project 4: Data Dashboard
#Problem Statement
Build a data analysis dashboard that loads a CSV dataset, computes summary statistics, identifies patterns, and generates a text-based report. This project simulates the kind of exploratory data analysis (EDA) that every data scientist does before building ML models.
You will work with a student performance dataset and answer questions like: What is the average score? Which subjects are hardest? Is there a correlation between study hours and grades?
#Concepts Used
- pandas — DataFrames, groupby, describe (from the NumPy & Pandas lesson)
- Functions — organized analysis pipeline (from the Functions lesson)
- String formatting — clean report output
- Dictionaries — aggregating results
#Starter Code
Tests · Fill in each analysis function, then run generate_report. You should see a multi-section text dashboard with statistics and insights.
#Challenge Extensions
- Grade distribution histogram. A text-based histogram showing how many students fall in each grade range (A: 90-100, B: 80-89, C: 70-79, D: 60-69)
- Subject correlation. Compute the correlation between each pair of subjects
- Pass/fail analysis. Define a passing score (e.g., 70) and report the pass rate for each subject
- Percentile ranks. For each student, compute their percentile rank in each subject
- Export report. Save the entire report to a text file using file I/O
#Project 5: CLI Quiz Game
#Problem Statement
Build a command-line quiz game with multiple-choice questions loaded from a data structure. The game tracks scores, provides feedback on each answer, and maintains a leaderboard. This project brings together OOP design patterns, decorators for timing, file I/O for persistence, and the random module for shuffling.
#Concepts Used
- OOP — Question, Quiz, and Leaderboard classes (from the Classes & OOP lesson)
- Decorators — timing decorator for quiz duration (from the Decorators & Generators lesson)
- File I/O — loading questions and saving the leaderboard (from the File I/O lesson)
- random — shuffling questions and answer order
- Data structures — lists, dicts, and sorting for the leaderboard
#Starter Code
Tests · Fill in the decorator and all 3 classes, then run to see a simulated quiz session with scoring and a leaderboard.
#Challenge Extensions
- Question categories. Add a
categoryfield and let the player choose - Difficulty levels — easy/medium/hard with point multipliers
- Streak bonus — bonus points for consecutive correct answers
- Timed questions — per-question time limit with point penalty
- Question bank file — load questions from JSON instead of hardcoding
#Design Wins You Just Practiced
#1. Decorator Pattern Adds Cross-Cutting Behavior
@timer decorator can wrap any function. Quiz logic stays focused on quiz behavior; timing is a separate, reusable wrapper. This is the same pattern FastAPI uses for route registration, Flask for view functions, and @functools.lru_cache for memoization.#2. Three-Class Decomposition
Question owns the what (text, options, correct answer). Quiz owns the flow (running through questions, scoring, results). Leaderboard owns the persistence (sorting, saving, loading). None of these classes need to know much about the others' internals — they communicate through small interfaces.#3. Pipeline Architecture in the Dashboard
generate_report is a pipeline: each section function is independent and writes to stdout. Adding a new analysis is one new function plus one line in generate_report. This is the same shape as a real ML pipeline (load → clean → engineer features → train → evaluate).#Next Stop: The Capstone
In the Data Dashboard, why is each analysis function separate rather than one giant function?