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
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
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
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
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.