AP CSP Topic 3.12 Guided Notes - Calling Procedures
Big Idea 3: Algorithms and Programming · Topic 3.12 · Guided Notes (Student)
Calling Procedures — Guided Notes
Fill these in during class or catch up here if you were absent. Print this page or work on paper — then check yourself with the CFUs on the Topic 3.12 page.
Print these notesAll CSP topics
Day 1: Push the Button, Trust the Box
Today’s objectives
- Write a statement that calls a procedure — procName(arg1, arg2, ...) — matching each argument to its parameter in order, and use DISPLAY to show a value (LO AAP-3.A)
- Determine the effect of a procedure call by tracing how the flow of control interrupts the main program, runs the procedure, and returns to the calling point (LO AAP-3.A)
Bell ringer
You are training a new snack-bar worker. Instead of re-explaining a combo every time, you write ONE instruction card titled makeCombo that lists the steps, leaving two blanks: the snack and the drink. Now you just say 'makeCombo with Nachos and Cola,' then later 'makeCombo with Popcorn and Water.'
Write 2–4 sentences: What did giving the card a NAME let you stop repeating? The two blanks on the card versus the actual words you say out loud each time — what is the difference between them? What has to happen the instant you say 'makeCombo' before the worker can continue with anything else?
01. What a Procedure Is & How You Call One
Key Vocabulary (LO AAP-3.A)
| Term | Definition (write it) |
|---|---|
| Procedure | |
| Method / function | |
| Parameter | |
| Argument | |
| Procedure call | |
| DISPLAY(expression) |
A Procedure Is a Named, Reusable Process
- A procedure lets you avoid copy-pasting a process because you can rerun it just by .
- Seeing the words 'method' or 'function' in another language should tell you that .
- In this topic your job is to , while writing your own procedures waits for Topic 3.13.
Call It by Name, Hand It Arguments
showItem is already written; the last line CALLS it, sending "Popcorn" to item and 3 to price.
AP Pseudocode (what the exam tests)
PROCEDURE showItem(item, price)
{
DISPLAY(item)
DISPLAY(price)
}
showItem("Popcorn", 3)
Python (the runnable version)
def showItem(item, price):
print(item, end=" ")
print(price, end=" ")
showItem("Popcorn", 3)
Output
Popcorn 3
Run and edit this yourself in the coding exercises for this topic.
Parameter vs. Argument — the Line Everyone Blurs
Parameter
Argument
- A parameter is best thought of as a placeholder because, until the procedure is called, it .
- The values written in the parentheses of a call are supplied fresh every time, which is why they are the .
- Calling showItem(2, "Cola") instead of showItem("Cola", 2) puts the wrong values in the parameters because arguments bind by .
AP TIP: Same slot, two roles. The parameter is the variable that receives; the argument is the value that is sent. Position decides the pairing — not the names.
Stop and think
- In one sentence, define a procedure using the word 'named,' then state the two other words languages use for the same idea.
- For the call greet("Sam", 5): if the definition is PROCEDURE greet(name, times), which values are the arguments, which words are the parameters, and what value does times receive?
- A classmate writes showItem(3, "Popcorn") expecting the same output as showItem("Popcorn", 3). Explain, using the word 'position,' why the two calls are not the same.
Answer in complete sentences. Then check yourself with the matching CFUs on the Topic 3.12 page.
02. Flow of Control & DISPLAY
A Call Is a Detour: Interrupt, Run, Return
- The moment a call executes, the main program's normal top-to-bottom sequence is .
- While a procedure runs, the computer is executing , not the main program's next line.
- The reason you can drop a call anywhere and keep going is that control comes back to .
Watch Control Leave and Come Back
showItem is the same procedure from before; the call sits between two DISPLAY lines in the main program.
AP Pseudocode (what the exam tests)
DISPLAY("Start")
showItem("Cola", 2)
DISPLAY("Done")
Python (the runnable version)
print("Start", end=" ")
showItem("Cola", 2)
print("Done", end=" ")
Output
Start Cola 2 Done
Run and edit this yourself in the coding exercises for this topic.
Trace the Output, Line by Line
Main program: DISPLAY("Start"); showItem("Cola", 2); DISPLAY("Done"). showItem does DISPLAY(item) then DISPLAY(price). Fill in the missing cells — remember DISPLAY adds a space after each value.
Complete the empty cells.
| Step | Statement executing | Where control is | Output so far |
|---|---|---|---|
| 1 | DISPLAY("Start") | Main program | Start |
| 2 | showItem("Cola", 2) | Start | |
| 3 | DISPLAY(item) | Inside showItem (item is "Cola") | |
| 4 | DISPLAY(price) | Inside showItem (price is 2) | Start Cola 2 |
| 5 | procedure ends | Control returns to after the call | Start Cola 2 |
| 6 | DISPLAY("Done") | Main program resumes |
Watch out — “The Argument Name Must Match the Parameter Name”
Myth: When you call a procedure, the variable or value you pass in has to have the same name as the parameter, or the values will not line up.
Explain why this is wrong:
Stop and think
- Trace and give the exact output: DISPLAY("A"); showItem("Chips", 4); DISPLAY("B"). Mark where control leaves the main program and where it returns.
- The procedure runs its two DISPLAY lines but prints nothing at the moment of the CALL itself. In one sentence, explain what the call statement actually does before any of the procedure's own lines run.
- A program has ten lines and line 4 is a procedure call. In one sentence, state which line runs next after the procedure finishes, and why.
Answer in complete sentences. Then check yourself with the matching CFUs on the Topic 3.12 page.
Today in one box
- A procedure is a named group of instructions — called a method or function in other languages — and today you CALL ones already written
- Parameters are the placeholders in the definition; arguments are the actual values at the call, matched by POSITION
- A call interrupts the main program, runs the procedure, and returns control to the point right after the call
- DISPLAY(expression) shows the value of expression followed by a space
Before next class: Before tomorrow, predict it: a procedure costFor(count) does RETURN(count * 3). What is the difference between DISPLAY(costFor(2)) and total ← costFor(2)? Which one lets you REUSE the answer later — and why?
Day 2: Getting Something Back
Today’s objectives
- Determine the value a procedure returns via RETURN(expression), and capture it with result ← procName(arg1, ...) so it can be reused (LO AAP-3.A)
- Write a call that reads a value from the user with INPUT() and passes it to a procedure, then determine the resulting effect (LO AAP-3.A)
Bell ringer
A procedure costFor(count) does one thing: RETURN(count * 3) — three dollars per snack. Consider two programs. Program A: DISPLAY(costFor(2)). Program B: total ← costFor(2), and nothing else.
Write 2–4 sentences: What does Program A put on the screen? What does Program B put on the screen? After each program runs, which one still 'has' the number 6 available to use again later, and why does that matter?
01. Getting a Value Back: RETURN & Capturing It
RETURN Hands a Value Back to the Caller
- RETURN(expression) sends the value back to the caller and also .
- After a procedure returns, the call itself that returned value.
- Writing more code after a RETURN is pointless because RETURN .
Return a Value, Then Store It
costFor returns count × 3; total ← costFor(4) captures the returned 12 so DISPLAY can show it.
AP Pseudocode (what the exam tests)
PROCEDURE costFor(count)
{
RETURN(count * 3)
}
total ← costFor(4)
DISPLAY(total)
Python (the runnable version)
def costFor(count): return count * 3 total = costFor(4) print(total, end=" ")
Output
12
Run and edit this yourself in the coding exercises for this topic.
DISPLAY vs. RETURN — Effect vs. Value
DISPLAY — an EFFECT
RETURN — a VALUE
- DISPLAY produces an effect: it shows a value and then the program .
- RETURN produces a value the caller can .
- To decide if a value survives a line, ask whether the program afterward.
AP TIP: Ask 'does the program still HAVE the value afterward?' DISPLAY: no, it only showed it. RETURN + capture: yes, it is stored. Only captured values can be reused.
Trace the Captured Return Values
costFor(count) returns count × 3. Fill in the missing cells as each call returns and each variable is assigned.
Complete the empty cells.
| Line | Statement | Value the call returns | Variable now holds |
|---|---|---|---|
| 1 | popcorn ← costFor(2) | popcorn = 6 | |
| 2 | drinks ← costFor(3) | 9 | |
| 3 | order ← popcorn + drinks | no call — plain arithmetic | |
| 4 | DISPLAY(order) | no call returns a value | prints 15 (order unchanged) |
Stop and think
- costFor(count) returns count × 3. Give the exact screen output of DISPLAY(costFor(5)), and separately explain what x ← costFor(5) puts on the screen and what it stores.
- In one sentence, name the two things RETURN(expression) does at the same time.
- A classmate writes DISPLAY(costFor(2)) and then tries to use that displayed 6 on the next line. Explain why the 6 is not available, and rewrite the first line so it is.
Answer in complete sentences. Then check yourself with the matching CFUs on the Topic 3.12 page.
02. Input From the User: INPUT()
INPUT() Returns Whatever the User Provides
- Unlike a literal such as 3, the value INPUT() supplies is not known until .
- Because INPUT() hands a value back, you handle it by .
- A value captured from INPUT() can then be .
Read, Call, Display
The user types a count; INPUT() returns it, costFor uses it, and DISPLAY shows the total. Shown: the user enters 5.
AP Pseudocode (what the exam tests)
count ← INPUT() total ← costFor(count) DISPLAY(total)
Python (the runnable version)
count = int(input()) total = costFor(count) print(total, end=" ")
Output
15
Run and edit this yourself in the coding exercises for this topic.
Watch out — “If a Procedure DISPLAYs a Value, I Can Store It”
Myth: A procedure that ends with DISPLAY(answer) is handing that answer back, so I can write x ← theProcedure() and x will hold the displayed value.
Explain why this is wrong:
Stop and think
- For count ← INPUT(); total ← costFor(count); DISPLAY(total), where costFor returns count × 3: if the user types 4, what is displayed? If the user types 10?
- In one sentence, explain why the output of an INPUT()-driven program can differ from one run to the next even though the code never changes.
- A procedure's whole body is DISPLAY(count * 3). A student writes answer ← thatProcedure(2) and expects answer to hold 6. Explain what answer actually holds and why, then state the one change that would make the capture work.
Answer in complete sentences. Then check yourself with the matching CFUs on the Topic 3.12 page.
Common AP Traps
Three ways Topic 3.12 loses points on the exam — one minute now, real points in May.
Arguments bind by POSITION, not name — in your own words:
DISPLAY ≠ RETURN — in your own words:
A call is a detour, and DISPLAY adds a space — in your own words:
Calling Procedures, in One Slide
- A procedure is a named group of instructions (a method/function elsewhere); you call it with procName(arg1, arg2...), arguments matched to parameters by position.
- A call interrupts the main program, runs the procedure, and returns control to the point right after the call; DISPLAY(expression) shows a value followed by a space.
- RETURN(expression) returns flow of control AND a value; result ← procName(...) captures that value so it can be reused.
- INPUT accepts a value from the user and returns it, so it can be captured and passed to a procedure.
Exit check — I can…
- ☐ write a statement that calls a procedure, matching each argument to its parameter by position (LO AAP-3.A)
- ☐ trace how a call interrupts the main program, runs the procedure, and returns control, and read DISPLAY output (LO AAP-3.A)
- ☐ determine the value a procedure returns with RETURN and capture it with result ← procName(...) for reuse (LO AAP-3.A)
- ☐ read a value with INPUT() and pass it to a procedure, and explain why DISPLAY is not the same as RETURN (LO AAP-3.A)
Get in Touch
Whether you're a student, parent, or teacher — I'd love to hear from you.
Just want free AP CS resources?
Enter your email below and check the subscribe box — no message needed. Students get daily practice questions and study tips. Teachers get curriculum resources and teaching strategies.
Message Sent!
Thanks for reaching out. I'll get back to you within 24 hours.
Prefer email? Reach me directly at [email protected]