Complete solutions to Harvard's CS50P — every problem set implemented and verified, with pytest suites passing — an independent, from-scratch build that is part of a csdiy.wiki full-catalog effort.
CS50P (CS50's Introduction to Programming with Python) is Harvard's introduction to programming, taught by David J. Malan. It covers functions and variables, conditionals, loops, exceptions, libraries, unit tests, file I/O, regular expressions, and object-oriented programming, ending with an open-ended final project.
This repository implements all 43 problems across the 9 problem sets plus a
substantive final project. Every solution runs end-to-end; the problems that ship
with (or require) test_*.py are covered by real pytest suites, and every program was
executed on sample inputs with the output captured to results/.
All 46 unit tests pass across 10 pytest suites (full log:
results/pytest.txt):
| Suite | Tests | Result |
|---|---|---|
pset5/test_twttr |
4 | passed |
pset5/test_bank |
3 | passed |
pset5/test_plates |
5 | passed |
pset5/test_fuel |
5 | passed |
pset7/numb3rs |
3 | passed |
pset7/working |
5 | passed |
pset7/um |
4 | passed |
pset8/jar |
4 | passed |
pset8/seasons |
4 | passed |
project |
9 | passed |
| Total | 46 | 46 passed |
Selected real program runs (full log:
results/sample_runs.txt):
$ echo "Hello :) Goodbye :(" | python pset0/faces/faces.py
Hello 🙂 Goodbye 🙁
$ python pset4/bitcoin/bitcoin.py 2.5 # live price from CoinGecko
$158,167.5000
$ python pset6/pizza/pizza.py regular.csv
+-----------------+---------+---------+
| Regular Pizza | Small | Large |
+=================+=========+=========+
| Cheese | $13 | $26 |
+-----------------+---------+---------+
| Mushroom | $14 | $28 |
+-----------------+---------+---------+
$ echo "2001-01-01" | python pset8/seasons/seasons.py
Five hundred twenty-five thousand, six hundred minutes
The pset8/shirtificate program renders a real A4 PDF certificate; a generated sample
is saved at results/shirtificate_sample.pdf.
- Pset 0 — Functions, Variables: indoor, playback, faces, einstein, tip
- Pset 1 — Conditionals: deep, bank, extensions, interpreter, meal
- Pset 2 — Loops: camel, coke, twttr, plates, nutrition
- Pset 3 — Exceptions: fuel, taqueria, grocery, outdated
- Pset 4 — Libraries: emojize, figlet, adieu, game, professor, bitcoin
- Pset 5 — Unit Tests: test_twttr, test_bank, test_plates, test_fuel
- Pset 6 — File I/O: lines, pizza, scourgify, shirt
- Pset 7 — Regular Expressions: numb3rs, watch, working, um, response
- Pset 8 — OOP: seasons, jar, shirtificate
- Final Project: a command-line task tracker (
project/)
cs50p/
├── pset0/ indoor playback faces einstein tip
├── pset1/ deep bank extensions interpreter meal
├── pset2/ camel coke twttr plates nutrition
├── pset3/ fuel taqueria grocery outdated
├── pset4/ emojize figlet adieu game professor bitcoin
├── pset5/ test_twttr test_bank test_plates test_fuel (each: <prog>.py + test_<prog>.py)
├── pset6/ lines pizza scourgify shirt
├── pset7/ numb3rs watch working um response (numb3rs/working/um ship pytest suites)
├── pset8/ seasons jar shirtificate (seasons/jar ship pytest suites)
├── project/ project.py test_project.py requirements.txt
├── results/ pytest.txt sample_runs.txt shirtificate_sample.pdf
├── requirements.txt
└── LICENSE
# Python 3.11. Install the dependencies the solutions actually import:
python -m pip install -r requirements.txt
# (this repo was built against the shared csdiy env:
# D:\Project\_csdiy\.venv-ml\Scripts\python.exe)
# Run any program (each lives in its own folder):
python pset0/tip/tip.py
python pset4/bitcoin/bitcoin.py 2.5
python pset6/pizza/pizza.py pset6/pizza/regular.csv
# Run a test suite (cd into the problem's folder so imports resolve):
cd pset8/jar && pytest
cd project && pytestSome programs need a data file that is provided in the folder (e.g. pset6/pizza/regular.csv,
pset8/shirtificate/shirtificate.png, pset6/shirt/shirt.png).
- Unit tests:
pytestwas run in every folder that contains atest_*.py; all 46 tests pass. Full transcript inresults/pytest.txt. - Real runs: every program was executed on representative inputs (including error
paths — bad command-line args, invalid dates, out-of-range fuel fractions) and the
outputs captured to
results/sample_runs.txt. - Live API:
bitcoin.pywas run against the CoinGecko public API and returned a real USD-denominated total. - Binary artifacts:
shirtificate.pyproduced a valid%PDF-1.4file (65 KB), andshirt.pyproduced a fitted JPEG overlay — both verified by re-opening with Pillow.
A small but complete command-line to-do manager (project/project.py) that exercises
most of the course's ideas at once: argparse sub-commands, JSON file persistence,
exception handling, regex/datetime date validation, and priority-based sorting.
python project/project.py add "Submit CS50P project" --priority high --due 2026-12-31
python project/project.py list --pending
python project/project.py done 1
python project/project.py remove 2It has a dedicated pytest suite (test_project.py, 9 tests) covering task creation, due-date
validation, priority/status sorting, completion, and removal.
Python 3.11 · pytest · emoji · inflect · pyfiglet · requests · tabulate · Pillow ·
fpdf2 · validators (standard library: re, csv, json, argparse, datetime, sys).
- Writing pure, testable helper functions (separating I/O from logic) so
pytestcan drive them directly — the whole point of Pset 5. - Robust input validation with
try/exceptand re-prompting (fuel, outdated, professor). - Regular expressions with
re.fullmatch/re.findalland word boundaries for IPv4 validation, YouTube URL extraction, and word counting. - Object-oriented design with
@property-guarded invariants (theJarclass). - Using third-party libraries idiomatically:
tabulatefor tables,fpdf2for PDFs,Pillowfor image compositing,inflectfor number-to-words.
Based on the problem sets of CS50's Introduction to Programming with Python (CS50P) by David J. Malan and Harvard University. This repository is an independent educational reimplementation; all course materials, specifications, and provided assets belong to their original authors. Original code here is released under the MIT License.