Week 4 — Yes-or-No Questions, Branches, and the Order of the Tests — Traditional alternative (no AI)
Instructors: publish this instead of the adaptive version if you prefer, and unpublish or delete the adaptive one.
Assignment 4 of the term — ask yes-or-no questions with comparisons, read a truth table, trace which branch of an if, elif, and else chain runs, find a logic error, and explain it all to someone who has never programmed.
This week you learned to ask yes-or-no questions with comparison operators, to combine them with and, or, and not, to read a truth table, and to let an if, elif, and else chain choose one branch. In this assignment you trace four short problems, run each one to check your prediction, run a few more programs that test the edges of a condition, and explain a real mix-up to someone who has never programmed. This builds on Week 2's floor division. This week's lecture tutorial, quiz, discussion, and Coding Lab practise the same ideas from other angles.
The task
A friend who coordinates a neighbourhood reading challenge has been using a short program to send readers a message, and something seems off. A reader with 45 pages logged was told Keep going, and a second program that turns a total into a letter told someone with 95 that they earned D or better. Your friend asks, "Is the computer broken?" Your job is to check what Python really did, the way a programmer would: predict each result before you run it, run it in a free browser Python runner, and explain what happened. All four problems are illustrative and use this week's reading log, where goal = 300 and pages_read = 45, and this week's truth tables.
Work these four problems. For each one, write your prediction first, then run the code and write the actual output beside your prediction:
- In the reading log's Week 4 stage,
goal = 300and the elif line testspages_read >= goal // 2. What number doesgoal // 2give, the halfway line that test compares against? - With
goal = 300andpages_read = 45, how many more pages must be read before the elif testpages_read >= goal // 2first comes outTrue? - Down the four rows of a truth table, in the order True True, True False, False True, False False, on how many rows does
not a or bgiveTrue? - A chain sets
total = 95and teststotal >= 60(printingD or better) beforetotal >= 90(printingA). For how many whole-number totals from 90 to 100, counting both ends, does it printD or betterinstead ofA?
Beside each answer, add one brief interpretation:
- Problem 1: explain why the program uses floor division
//to find the halfway line, and run the reading log's Week 4 stage withpages_read = 150; say which message prints and why>=counts a value equal to the line. - Problem 2: run the program with
pages_read = 149and then withpages_read = 150, report both messages, and explain why the test uses>=rather than>for a reader who lands exactly on the halfway line. - Problem 3: name the one row that gives
Falseand explain it with the priority not, then and, then or; then runnot (a or b)down the same four rows, report what it prints, and say why the two columns differ. - Problem 4: name the family this bug belongs to (a syntax error, a runtime error, or a logic error) and say how you can tell; then reorder the two tests, run the chain with
total = 95again, and report what it prints.
Explain it to a non-programmer
Write a 3–5 sentence message to your friend that explains, in everyday words, why the letter program told someone with 95 that they earned D or better, and how putting the stricter test first fixes it. Use the idea that the program checks its questions from the top and stops at the first one that comes out True, and name one limit or caveat, such as checking a value right at a cutoff after the fix. Explain any technical term in everyday words. More than one good message is possible.
For a different, ungraded example, imagine a teammate whose sign-up form rejected the eight-letter password sunshine with the message Too short, even though the rule says eight characters is enough. Model message: "The form asked whether the password was longer than 8 characters, and sunshine has exactly 8, so the answer came back no. The rule meant at least 8, which is a slightly different question that includes 8 itself. Changing the test from longer than to at least makes sunshine pass. One catch: after a fix like this, try a password of exactly 7, 8, and 9 characters, because the edge of a rule is where mistakes hide."
Use that pattern for your friend's question, with your own wording and evidence.
Show your traces. A reader should be able to follow every prediction step by step and see the actual output of your run beside it, without guessing which values, tests, or branches you used.
Deliverables
Submit a single report containing:
- the four answers, each with your prediction, the step-by-step trace, the actual output of your run, and the brief interpretation the task names for that problem;
- the runs of the reading log's Week 4 stage with
pages_read = 149and withpages_read = 150, ofnot (a or b)down the four rows, and of the reordered chain withtotal = 95, each with what printed; and - your message to your friend, explaining why the letter program printed
D or betterfor 95, how putting the stricter test first fixes it, and one limit.
Keep it to roughly one page. Clear and correct beats long.
Choose how you show it. Present your report as written text, or as a recorded audio or video explanation of about three minutes with a transcript, or as labelled screen captures of your runs with a short note for each. Every form is graded by the same scoring criteria. Submit in any accessible file type or as a link; a recorded response may be submitted as audio or video with a transcript, or as text.
How you'll be graded
The full analytic rubric is attached to this assignment in Canvas.
Academic integrity and AI use
This version is designed to be completed without AI: make the predictions, run the code, and write the interpretations and the message yourself, without any AI tool. You may use a free browser Python runner, Python Tutor, and the official Python documentation. Submitting AI-generated work as your own, or copying another student's work, is an integrity violation under the course policy.
Built with The Course Maker · samples.thecoursemaker.com