Level 0 / Project 12 - Contact Card Builder¶
Home: README
Learn Your Way¶
| Read | Build | Watch | Test | Review | Visualize | Try |
|---|---|---|---|---|---|---|
| Concept | This project | — | Quiz | Flashcards | Diagram | Browser |
Estimated time: 25 minutes
Focus¶
- dictionary creation and formatting
Why this project exists¶
Parse comma-separated contact records into structured dictionaries and display them as formatted cards with box borders. You will practise string splitting, dictionary construction, and text alignment.
Run (copy/paste)¶
Use <repo-root> as the folder containing this repository's README.md.
cd <repo-root>/projects/level-0/12-contact-card-builder
python project.py --input data/sample_input.txt
pytest -q
Expected terminal output¶
=== Contact Cards ===
+---------------------------+
| Ada Lovelace |
| Phone: 555-0101 |
| Email: ada@example.com |
+---------------------------+
Parsed 3 valid contacts (0 errors)
Output written to data/contacts.json
5 passed
Expected artifacts¶
data/output.json- Passing tests
- Updated
notes.md
Checkpoint: Baseline code runs and all tests pass. Commit your work before continuing.
Alter it (required) — Extension¶
- Add a phone number field (4th comma-separated value) to the contact card format.
- Add a
--formatflag to choose between "card" (box drawing) and "csv" (plain comma-separated) output. - Re-run script and tests.
Break it (required) — Core¶
- Add a line with only a name and no email like
John Smith-- doesparse_contact_line()raiseValueError? - Add a line with an invalid email like
alice@-- does the email validator catch it? - Add a line with extra commas like
Name, Role, email@test.com, , ,-- what happens?
Fix it (required) — Core¶
- Ensure
parse_contact_line()raisesValueErrorwith a clear message for lines with fewer than 3 fields. - Improve email validation to reject emails without a domain part.
- Add a test for the malformed-line edge case.
Checkpoint: All modifications done, tests still pass. Good time to review your changes.
Explain it (teach-back)¶
- Why does
parse_contact_line()use.split(",")and then.strip()each part? - What does the
"@" in email and "." in emailcheck actually validate (and what does it miss)? - Why does
format_card()use box-drawing characters for the border? - Where would contact card parsing appear in real software (CRM imports, vCard generation, address books)?
Mastery check¶
You can move on when you can: - run baseline without docs, - explain one core function line-by-line, - break and recover in one session, - keep tests passing after your change.
Related Concepts¶
- Classes and Objects
- Collections Explained
- Files and Paths
- Functions Explained
- Quiz: Classes and Objects
| ← Prev | Home | Next → |
|---|---|---|