← Back to the Introduction to Computer Science outline The Course Maker
← Introduction to Computer Science outline
Week 6 · Discussion: Traditional alternative (no AI)

Week 6 Discussion — Which Loop Fits the Job? — Traditional alternative (no AI)

Introduction to Computer Science Free sample edition
Traditional alternative (no AI), unpublished. In the course this is a separate discussion that ships unpublished beside the adaptive discussion: same objective, no AI. An instructor who prefers it publishes it and unpublishes or deletes the adaptive one, as the note at its top says.

Instructors: publish this instead of the adaptive version if you prefer, and unpublish or delete the adaptive one.

Hook

A pill organizer has seven boxes, so you fill seven and stop; a kettle heats until the water boils, and nobody knows the count ahead of time. This week you learned that a for loop makes one pass per item it is handed, that a range stops before its stop, and that a loop inside a loop multiplies its passes, so a 2 by 3 nested loop prints 2 × 3 = 6 lines.

Your discussion question — choose Option A or Option B; they carry the same weight and the same rubric, and you say which you picked.

Option A: Pick a repeated task from your own life, major, or workplace, such as hourly checks on a shift, laps at practice, or rows on a seating chart. Argue whether a program for it should be written as a for loop over a fixed range or as a while loop that tests a condition, write the range or the condition you would use, and say what could go wrong with your choice, such as a range that stops one short. Use this week's ideas (the for loop, the loop variable, range() and its exclusive stop, and range(n) versus range(1, n + 1)) and say what someone who would pick the other kind of loop would argue.

Option B: A nested loop multiplies: an outer loop over the rows of a grid and an inner loop over its columns visits every cell, and the count of passes is outer times inner. Take a position on when a design that checks every combination, such as every seat in every row or every pair of time slots in a schedule, is the right approach, and when the multiplied count should make a programmer stop and look for a different plan. Use this week's ideas (nested loop, outer loop, inner loop, and counting lines of output as outer passes times inner passes) and say what someone who weighs thoroughness differently from you would argue.

There is no single right answer. People who agree on every fact about how Python runs a loop still disagree about which loop fits a task and how much repetition is too much, because those questions rest on judgment about the task as well as on the facts. Pick the option you actually care about, and make your case.

Expectations

Activity format: one initial post followed by two substantive peer replies. Plan on about 45 minutes across the two deadlines; your instructor sets both due dates in Canvas.

Your initial post — by the first due date (early in the module week):

  • Say which option you chose.
  • For Option A, name the task, write the range or the condition you would use, say which numbers the range produces or when the condition turns False, and explain why that kind of loop fits; for Option B, name a check-every-combination design, count its passes as outer times inner for one small example, and say when that count is acceptable and when it is a reason to rethink.
  • Use at least two of this week's terms (for loop, loop variable, range(), exclusive stop, nested loop, outer loop, inner loop) correctly.
  • State the strongest case for a view you do not hold, in one or two sentences.
  • Length: roughly 150–250 words if written. You may instead record your post as audio or video (about two minutes) and attach a transcript; both forms are scored by the same rubric.

Your replies — by the second due date (the end of the module week):

  • Reply substantively to at least two classmates.
  • A substantive reply does more than agree: run their range with list() and report the numbers it holds, point out a stopping point their loop would miss, or make the strongest fair case for the side they did not take. "Nice point!" on its own does not count.

What a strong post looks like:

I chose Option A. A shelter volunteer feeds the animals on each of the 5 shifts in a day, so the count is known before the day starts, and I would write for shift in range(1, 6), which hands the loop 1, 2, 3, 4, and 5. A while loop could work, but it adds a counter I could forget to move. The risk with my choice is writing range(1, 5) and silently skipping the last shift. Someone could argue a while loop is better because a shift can be cancelled, and that is fair, but the cancellation could be a check inside my for loop.

Notice how it names the exact range, lists the numbers it produces, names the off-by-one risk, takes a position, and states a fair case for the other side. That is the bar.

Participation rubric

This discussion is worth 10 points. The three criteria below look at your initial post and your peer replies.

How the 10 points of this discussion are earned
Criterion Full credit Partial credit No credit
Quality of the initial post (4 pts) A specific task or design, with the exact range, condition, or pass count written out, a clear position with a reason, and a fair statement of another view A task is present, but the range or count stays vague, or the position is asserted without a reason Missing, off-topic, or no reasoning about which loop fits or how passes multiply
Use of course concepts (3 pts) Uses for loop, range(), exclusive stop, and nested loop precisely, with every range read correctly Uses a term loosely, or reads a range as including its stop No course terms, or used incorrectly
Engagement with peers (3 pts) Two or more substantive replies that extend or challenge a classmate's reasoning One substantive reply, or replies that only agree No replies, or "I agree" with nothing added

Post early if you can — the best threads happen when people have time to reply before the second due date.

Built with The Course Maker · samples.thecoursemaker.com