Level 0 / Project 04 - Yes No Questionnaire¶
Home: README
Try in Browser: Run this exercise online — no installation needed!
Before You Start¶
Recall these prerequisites before diving in:
- Can you use .strip() and .lower() to clean up a string?
- Can you check if a value is in a set? ("yes" in {"yes", "y", "true"})
Estimated time: 20 minutes
Learn Your Way¶
| Read | Build | Watch | Test | Review | Visualize | Try |
|---|---|---|---|---|---|---|
| Concept | This project | — | Quiz | Flashcards | Diagram | Browser |
Focus¶
- boolean logic and input normalization
Why this project exists¶
Process yes/no survey answers, normalise messy input like "YES", "y", "True" into clean booleans, and tally the results with percentages. You will learn input normalisation and basic statistics.
Run (copy/paste)¶
Use <repo-root> as the folder containing this repository's README.md.
The program asks you 5 questions interactively and tallies your answers.
Expected terminal output¶
=== Yes/No Questionnaire ===
Answer 5 questions with yes or no.
1. Do you enjoy learning new things? yes
2. Have you used a computer before today? y
3. Do you like solving puzzles? yeah
4. Are you excited to learn Python? YES
5. Do you prefer working alone? no
=== Results ===
Total responses: 5
Yes: 4 (80.0%)
No: 1 (20.0%)
Invalid: 0
5 passed
Expected artifacts¶
- Passing tests
- Updated
notes.md
Checkpoint: Baseline code runs and all tests pass. Commit your work before continuing.
Alter it (required) — Extension¶
- Add "maybe" as a third valid answer category (accept "maybe", "perhaps", "unsure").
- Add a percentage bar using
#characters next to each tally count. - Re-run script and tests.
Break it (required) — Core¶
- Answer every question with just spaces or blank -- does
tally_answers()crash or return zeros? - Answer with "YES!!!" or "y e s" -- does
normalise_answer()handle them? - What happens if you call
tally_answers([])with an empty list?
Fix it (required) — Core¶
- Handle the empty-answers case by returning a tally with all zeros.
- Strip punctuation from answers so "YES!!!" normalises to "yes".
- Add a test for the all-blank-answers edge case.
Checkpoint: All modifications done, tests still pass. Good time to review your changes.
Explain it (teach-back)¶
- Why does
normalise_answer()use.strip().lower()before checking membership in a set? - What is the difference between checking
answer in {"yes", "y", "true"}vs using if/elif? - Why return "invalid" for unrecognised answers instead of raising an error?
- Where would answer normalisation appear in real software (survey tools, form validation)?
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¶
Stuck? Ask AI¶
If you are stuck after trying for 20 minutes, use one of these prompts:
- "I am working on Yes No Questionnaire. I got this error: [paste error]. Can you explain what this error means without giving me the fix?"
- "I am trying to normalize messy input strings like 'YES', 'y', 'True' into a consistent format. Can you explain
.strip().lower()with examples that are not about yes/no answers?" - "Can you explain how to calculate a percentage from a count and a total, with a simple example?"
| ← Prev | Home | Next → |
|---|---|---|