Copy-paste is a warning sign. When the same lines show up three times, it’s time to write your own procedure — name a job once, then call it wherever you need it.
Focus on defining your own procedure and giving it parameters. Enrolled in our Runestone course? Open it from there so your progress counts.
Still in Programs. In 3.11 you called procedures other people wrote. Now you write your own — the exact skill the Create PT requires, and the tool that turns a sprawling program into a few readable lines.
Repeated code is a code smell — a sign
something wants to be a procedure. Write the four lines once as class_average(scores),
and now there’s one place to call, one place to fix, one name that says what it does. That is
what “managing complexity” means in practice.
You define a procedure with def (Python) or PROCEDURE (AP). The names in
the definition’s parentheses are parameters — placeholders. The values
you pass when you call it are arguments — the real values that fill
those placeholders.
def greet(name): —
name is a parameter). The argument is the value at the call
(greet("Sam") — "Sam" is the argument). Definition = parameter;
call = argument.
def triple(n): # n is a parameter return n * 3 answer = triple(5) # 5 is an argument print(answer) # 15
PROCEDURE triple(n) { RETURN (n * 3) } answer ← triple(5) DISPLAY(answer)
Hover or tap a line to light its twin. The definition (lines 1–2) just
describes the job — nothing runs yet. The code runs when you call it
(line 4), with 5 flowing into the parameter n. Result: 15.
Here’s a defined procedure triple(n). Call it with different arguments and watch
the same definition produce different results — that’s the whole point of a parameter.
Five questions. Watch the parameter/argument distinction and remember: defining a procedure doesn’t run it — calling it does. Then pick your answer.
No one writes a hundred-thousand-line program as one giant script.
They write hundreds of small procedures — send_email, check_password,
load_level — each named for its job, each testable alone, each reusable. The
names are the design: a good one lets a teammate use your code without reading it.
This is how teams build things no individual could hold in their head, and how you’ll build your Create PT: a couple of well-named procedures beat one tangled block every time. “Don’t repeat yourself” isn’t tidiness — it’s the difference between fixing a bug once and hunting it in five places.
return a value or only print one?