← Back to course
Code Crew G5 / Week 05 / Crew Quest
6/6
Week 05 Β· Loop or recursion?

Crew Quest

Crew Quest: Tally or tower
// The same job, two ways
⏱ about 15 min

Crew Quest: Tally or tower

Rocket and Raven hold a friendly race on the observation deck.

Rocket counts down from 5 by stacking cups into a tower, one cup per call. Raven counts down with tally marks in a single row.

"What do you notice about our two ways?" Raven asks when they both say Liftoff.

"My tower got tall, then came back down," Rocket says. "Your row just kept going."

Nova cheers for both. "Here is a hint. Think about what would happen if you counted from 50."

  1. A while loop repeats while its test is True.
  2. range(1, n + 1) makes the numbers from 1 to n.
  3. To turn a loop into recursion, find the stop, the smaller step and the work.
  4. Loops and recursion can give the same answer.
  5. Very deep recursion causes a RecursionError, so long lists fit a loop.
β—‡ TALLY OR TOWER
One person counts down from 5 by stacking cups or blocks, one per number.
At 0, they say Liftoff, then remove the cups one at a time.
The other person counts down from 5 with tally marks on paper.
Compare: which way needed more space at the deepest point?
Talk about what would happen with a countdown from 50.
For a grown-up
Plastic cups or toy blocks work well. The tower is like the call stack, and the tally row is like a loop.
RECAP QUESTION
  • Read the question.
  • Tap your answer.
You need to add 3,000 numbers. Which tool is safer?
Bonus recap statementTrue or false?
range(1, 6) makes 1, 2, 3, 4, 5.?
A loop can never give the same answer as a recursion.?
A while loop needs a change that leads to stopping.?
Very deep recursion can cause a RecursionError.?
WHY THIS EXERCISELoops and recursion are two shapes for the same ideas.
How many numbers are in range(1, 8)?
What does sum_to_loop(4) return?
What does boost(2, 3) return?

Quest complete! Next week we search the star catalog one star at a time.

← Friday