Python Projects
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
#How This Lesson Works
There are no new concepts here. You build two projects that combine what the earlier lessons taught. Each project has a problem statement, the concepts it uses, starter code with TODOs, a full solution and challenge extensions.
#Project 1: 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 Pandas Essentials 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 2: 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
#Challenge extensions for the mini-projects
The calculator, the contact book and the word counter are covered by mini-projects you have already built. Rather than repeat them, here are ways to push each one further. These are open tasks with no solution given; write your own tests or expected output before you start.
- Robust Calculator. Extend Mini-Project: Robust Calculator with a history list that works as a stack: append each result, and add
undo(pop the last entry) andredo(a second stack that holds what you undid). Then addpower,sqrtandmodulo, and parse an input line like"10 + 5"with.split(). - Todo App as a contact book. Take Mini-Project: Todo App and swap the task list for a
ContactBookclass that storesname -> {"phone": ..., "email": ...}in a dict and saves to JSON withjson.dump. Addsearch_partial(case-insensitive substring match),update_contact, a CSV export and validation of phone and email fields. For the class design, look back at Mini-Project: Bank Account Class. - Word Counter. Extend Mini-Project: Word Counter with a stop-word filter (a set of words to skip before counting),
Counter.most_common(n)for the top words, a text bar chart scaled to the longest bar, and bigram counts (pairs of consecutive words). Bonus: read the text from a file, and check whether rank times count is roughly constant (Zipf's law) on a long text. - Grade Statistics. Extend Mini-Project: Grade Statistics by loading the grades into a pandas DataFrame and reusing the dashboard functions above: per-subject mean and median, pass rate and a grade-band histogram.
#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?