AP CSP Topic 3.3 Coding Practice - Mathematical Expressions
Big Idea 3: Algorithms and Programming · Topic 3.3 · Coding Practice
Mathematical Expressions — 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 Evaluate the Order Slip and Fix the Pizza Math exercises. Now build and run the same pizza-party calculations — the problems get harder as you go, hardest last, ending with one you write from scratch. Predict the output first, then check yourself. Remember: the / operator gives the exact value (17 / 5 is 3.4), and MOD gives the remainder (17 MOD 5 is 2).
Problem 1 of 4
A party orders 3 pizzas, each cut into 8 slices. Store the two numbers in variables, then print the total number of slices. Print exactly: 24
Total slices is a multiplication: pizzas * slicesPerPizza. Store it, then print it — 3 * 8 is 24.
Problem 2 of 4
17 slices are shared as equally as possible among 5 friends. Print how many slices are LEFT OVER after everyone gets an equal whole number of slices. Print exactly: 2
Leftover means remainder, which is MOD (written % in Python and JavaScript). 17 MOD 5 is 2, because 5 goes into 17 three times with 2 to spare.
Problem 3 of 4
Show the exact share the / operator gives: 17 slices divided equally among 5 friends, allowing fractional slices. Print the exact value of 17 / 5. Print exactly: 3.4
The / operator keeps the decimal, so 17 / 5 is 3.4, not 3. This is the exact per-person share; MOD (from the previous problem) gave the leftover instead.
Problem 4 of 4
Write the Pizza Party Planner from scratch. There are 3 pizzas of 8 slices each, shared among 5 friends. Print the total number of slices on the first line, then the leftover slices on the second line. Print exactly: 24 4
Expected output: 24
4
Show AP pseudocode reference
pizzas ← 3
slicesPerPizza ← 8
friends ← 5
total ← pizzas * slicesPerPizza
DISPLAY(total)
leftover ← total MOD friends
DISPLAY(leftover)
Combine the earlier problems: total = pizzas * slicesPerPizza gives 24, then leftover = total MOD friends gives 24 MOD 5 = 4. Print each on its own line. If you write it as one expression, pizzas * slicesPerPizza MOD friends works because * and MOD are evaluated left to right.
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.