AP CSP Topic 3.12 Coding Practice - Calling Procedures

Big Idea 3: Algorithms and Programming · Topic 3.12 · Coding Practice

Calling Procedures — Code It Yourself

Write real code and check it against the expected output. Pick Python or JavaScript; the AP pseudocode reference is there when you need it.

You warmed these up on paper in the Trace the Call and Effect-or-Value exercises — same snack-bar procedures. Now type and run them for real, hardest last. The procedures are already written for you (or nearly so); your job is to CALL them, capture what they RETURN, and DISPLAY the result. Predict the output first, then check yourself.

Problem 1 of 4

The procedure costFor is already written: it returns count times 3 (each snack is $3). Call it with an order of 4 snacks and print the total, exactly: 12

Expected output: 12

Show AP pseudocode reference
PROCEDURE costFor(count)
{
  RETURN(count * 3)
}
total ← costFor(4)
DISPLAY(total)
Capture what the call hands back: total = costFor(4). The call runs the procedure, and total then holds the returned value 12, which you print.

Problem 2 of 4

Using the same costFor(count) that returns count times 3, a customer buys 2 popcorns and 3 drinks. Call costFor once for each, add the two returned totals, and print the order total, exactly: 15

Expected output: 15

Show AP pseudocode reference
PROCEDURE costFor(count)
{
  RETURN(count * 3)
}
popcorn ← costFor(2)
drinks ← costFor(3)
order ← popcorn + drinks
DISPLAY(order)
Capture each call in its own variable — popcorn = costFor(2) and drinks = costFor(3) — then add the two captured values. Only a value you captured can be reused in the sum.

Problem 3 of 4

The procedure label(name, count) is written for you; it prints the name then the count on one line. Watch argument ORDER: call it so the screen shows exactly: Nachos 2

Expected output: Nachos 2

Show AP pseudocode reference
PROCEDURE label(name, count)
{
  DISPLAY(name)
  DISPLAY(count)
}
label("Nachos", 2)
The first argument goes to the first parameter (name), the second to count. Put "Nachos" first and 2 second: label("Nachos", 2). Swapping them would print 2 Nachos.

Problem 4 of 4

Write it from scratch. A snack costs $3. Write a procedure named costFor that takes count and RETURNS count times 3. Then use it to price an order of 7 snacks and print the total, exactly: 21

Expected output: 21

Show AP pseudocode reference
PROCEDURE costFor(count)
{
  RETURN(count * 3)
}
total ← costFor(7)
DISPLAY(total)
First write the procedure with a return line (return count * 3). Then call costFor(7), store the returned value in a variable, and print that variable. The RETURN is what makes the value available to capture.

Your code runs on a secure external service. Answers are checked automatically — nothing is stored.

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.

Typically responds within 24 hours

Message Sent!

Thanks for reaching out. I'll get back to you within 24 hours.

🏫 Welcome, fellow educator!

I offer curriculum resources, practice materials, and study guides designed for AP CS teachers. Let me know what you're looking for — whether it's classroom materials, a guest speaker, or Teachers Pay Teachers resources.

Email

[email protected]

📚

Courses

AP CSA, CSP, & Cybersecurity

Response Time

Within 24 hours

Prefer email? Reach me directly at [email protected]