
Side Quest: Plan the Rescue
Good programmers often write the least new code. Before they write anything, they read the helpers that already exist and plan how to connect them.
A planning recipe
- List what the job needs, one line per need.
- For each need, find the helper that does exactly that. Read its name, its parameters (what it needs) and what it returns (what it gives back).
- Connect them: one helper's return value becomes the next helper's argument.
Watch the inputs. A helper that needs boats can only run after
you know how many boats there are. So the order of the lines is
part of the plan.
def boats_needed(people): # needs people, gives boats
return (people + 3) // 4 # rounds up: 5 people -> 2 boats
Pip tip: Read a helper's first line like a label on a tool box: what goes in, and what comes out?
Assignment
Storm! Islanders on Gull Rock need rescuing. The helpers are written for you. Don't change them.
plan_rescue(people, km) must return a tuple (boats, crew, oil):
- Every person needs a seat, and each boat seats 4.
- Each boat needs its own rowers.
- Every boat burns oil for the whole trip, there and back.
Fill each ___ with the right helper name or argument. Careful:
one helper is a decoy that only counts a single boat.
Storm! Islanders on Gull Rock need rescuing. The helpers are written for you. Don't change them.
plan_rescue(people, km) must return a tuple (boats, crew, oil):
- Every person needs a seat, and each boat seats 4.
- Each boat needs its own rowers.
- Every boat burns oil for the whole trip, there and back.
Fill each ___ with the right helper name or argument. Careful:
one helper is a decoy that only counts a single boat.
Press Run to try your code, then Check to test it.