Week 6 — Ranges, Totals, and Loops Inside Loops — Traditional alternative (no AI)
Instructors: publish this instead of the adaptive version if you prefer, and unpublish or delete the adaptive one.
Assignment 6 of the term — predict where a range stops, total numbers with a for loop, count the passes of a nested loop, and explain it all to someone who has never programmed.
This week you learned that a for loop makes one pass per item it is handed, that a range stops before its stop number, and that a loop inside a loop runs the whole inner loop on every outer pass. In this assignment you trace four short problems, run each one to check your prediction, run three more loops that show the exclusive stop, the bare print(), and range(n), and explain a real mix-up to someone who has never programmed. This builds on Week 5's counters and accumulators. This week's lecture tutorial, quiz, discussion, and Coding Lab practise the same ideas from other angles.
The task
A cousin who coaches a community swim club wrote a short program to call out the laps of a five-lap warm-up: for lap in range(1, 5): with print("Lap", lap) in the body. When your cousin ran it, the lap calls did not match the five-lap plan, and your cousin says, "Python must have skipped something." Your job is to check what Python really did, the way a programmer would: predict each output before you run it, run it in a free browser Python runner, and explain what happened. All four problems are illustrative; Problem 1 uses this week's reading log, which starts at pages_read = 45 and adds 30 pages a day.
Work these four problems. For each one, write your prediction first, then run the code and write the actual output beside your prediction:
- The reading log starts at 45 pages read and runs
for day in range(1, 8):, adding 30 pages on each pass and printing the day and the running total. What is the last number the program prints? - Your cousin's loop
for lap in range(1, 5):prints the word Lap and the lap number once per pass. How many lines does it print? - The star grid runs an outer loop over
range(3)and an inner loop overrange(4), printing one star per inner pass and a bareprint()after each row. How many stars does it print in all? - With
n = 5, a loop adds every number ofrange(1, n + 1)into a total that starts at 0. What total does it print?
Beside each answer, add one brief interpretation:
- Problem 1: state how many lines print inside the loop and why the stop 8 is never a day, and say what the unindented last
print(pages_read)adds. - Problem 2: name the lap that never prints and why the range leaves it out, and write the fixed range and run it to show every lap.
- Problem 3: explain why the inner loop runs on every pass of the outer loop. Then move the bare
print()four spaces left, out of the outer loop, run it, and say what the output shows. - Problem 4: run the same total over
range(n)instead, say what it prints, and explain which pattern counts from 1 to n.
Explain it to a non-programmer
Write a 3–5 sentence message to your cousin that explains, in everyday words, why the program did not call all five laps and how changing one number fixes it. Use the idea that a range stops before its stop number, and name one limit or caveat, such as what the loop would need if the warm-up changed length from week to week. Explain any technical term in everyday words. More than one good message is possible.
For a different, ungraded example, imagine a teammate whose program printed the name Ana on a name tag one letter per line, A, then n, then a, when the tag needed the whole name on one line. Model message: "Each time Python prints, it starts a new line afterward unless you tell it not to. The loop printed one letter per pass, so each letter landed on its own line. Adding end with empty quotes inside the print tells Python to put nothing after each letter, so the letters stay together, and one plain print at the end finishes the line. One catch: this only changes how the letters are laid out, not which letters print."
Use that pattern for your cousin'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 numbers a range produced or how many passes a loop made.
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 fixed lap loop, the star grid with the bare
print()moved out of the outer loop, and the total overrange(n), each with what printed; and - your message to your cousin, explaining why the program printed only four laps, how changing one number calls all five, 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