Unit 3 · Programming 2 · Lesson 3.11

Calling Procedures

You’ve been calling procedures since Week 5 — print, len, input — without naming what you were doing. Today we name it: give a procedure some values, get a result back, and don’t worry how.

Big Idea 3 — Algorithms & ProgrammingWeek 3 · Procedures

Before this lesson — read on Runestone

Focus on calling a procedure and using what it returns. We’ll write our own in 3.12. Enrolled in our Runestone course? Open it from there so your progress counts.

1

Where We Are

People→ Bits→ Programs→ Internet→ Security→ Big Data→ Impact

Still in Programs, opening Week 3. Loops and lists let you do a lot — but your programs are getting long and repetitive. Procedures are the tool for managing complexity: package a job once, call it by name whenever you need it.

2

The Hook

len(scores) You’ve typed things like this for weeks. You hand len a list, and it hands back a number. You have never once looked at how len counts — and you didn’t need to.

That’s a procedure call: values go in as arguments, a result comes out as a return value, and the messy middle is hidden. Today you learn to read that shape everywhere — including calls nested inside other calls.

3

The Idea

A procedure is a named block of code you can run by calling it. You pass it arguments (the values in the parentheses), it does its job, and it may hand back a return value.

CallArguments inReturns
len(scores)a listhow many elements
max(scores)a listthe largest element
round(3.7)a numberthe nearest whole number
Think of a procedure as a black box: you trust what goes in and what comes out, and you ignore the inside. That’s the abstraction ladder again (1.7, 3.6) — a name standing in for a whole process, so your brain can hold the big picture.

Python — nested calls

scores = [85, 90, 78]
print(len(scores))   # 3

Read it inside-out

# a list of 3 scores
# len(scores) runs FIRST → 3,
# then print(3) shows it

Hover or tap a line to light its twin. Nested calls run from the inside out. len(scores) becomes 3 first; then print receives that 3. Whenever you see calls inside calls, evaluate the innermost one first.

Procedure vs function — don’t sweat it. Some people say “function” when it returns a value and “procedure” when it just does something. AP Pseudocode calls them all procedures, and so will we. What matters is the shape: arguments in, work happens, a value may come out.
4

Try It — The Black Box

Feed a value to a built-in procedure and see what it returns — without ever seeing its insides. Then try a nested call and watch it evaluate inside-out.

on [ ]
call: —
returns: —
print(that) shows: —
5

Vocabulary

procedure Programs
A named block of code that performs a task, run by calling its name.
call Programs
To run a procedure by name, giving it any arguments it needs.
argument Programs
A value you pass into a procedure when you call it — the thing in the parentheses.
return value Programs
The result a procedure hands back to whoever called it.
6

Check

Five questions. For nested calls, evaluate the innermost one first. Then pick your answer.

0 of 5 answered
7

Impact Check

You already stand on a mountain of other people’s procedures

Every print, every input, every len is a procedure someone else wrote, tested, and handed you as a black box. Modern software is procedures calling procedures calling procedures — almost none of which any one programmer wrote. You built a working program in Week 2 on top of code you’ll never read, and that’s not cheating; it’s the whole design.

This is abstraction doing its most important job: letting humans build things far bigger than any one person could hold in their head. The catch is trust — when a black box has a bug or a bias, everyone standing on it inherits it. You’ll see that tension again with libraries (3.16) and AI (Unit 8).

8

Connections

Came from 1.7 & 3.6 — a procedure is the abstraction ladder again: a name hiding a whole process.
Next in 3.12 — you stop only calling other people’s procedures and start writing your own with def.
Returns in 3.13 — the crucial difference between a procedure that returns a value and one that only prints.
Returns on the exam — tracing nested calls like DISPLAY(LEN(list)) is a guaranteed question. Inside-out, every time.
← 3.10 Lab: Gradebook Day