AP CSP Topic 3.9 Coding Practice - Developing Algorithms

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

Developing Algorithms — 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 Trace and Compare and Build It from Blocks, using the Level Up game. Now type and run them for real — same building blocks, harder each time. The first is a straight building block; the last you assemble and modify yourself. Predict the output first, then check it.

Problem 1 of 4

Building block — MAX. Two players scored 88 and 95. Print the higher score.

Expected output: 95

Show AP pseudocode reference
a ← 88
b ← 95
IF(a > b) { higher ← a } ELSE { higher ← b }
DISPLAY(higher)
Compare a and b with an IF/ELSE: if a > b the higher is a, otherwise it is b. Print that value.

Problem 2 of 4

Building block — DIVISIBILITY. A coin appears on every 3rd tile. For tile = 12, print coin if 3 divides it evenly, otherwise print no coin.

Expected output: coin

Show AP pseudocode reference
tile ← 12
IF(tile MOD 3 = 0) { DISPLAY("coin") }
ELSE { DISPLAY("no coin") }
MOD (written % in Python and JavaScript) gives the remainder. A remainder of 0 means the division is exact, so 3 divides the tile evenly.

Problem 3 of 4

Combine blocks — AVERAGE, then PASS/FAIL. Three playtesters scored 80, 90, and 100. Compute their average, then print pass if the average is at least 60, otherwise fail.

Expected output: pass

Show AP pseudocode reference
s1 ← 80
s2 ← 90
s3 ← 100
avg ← (s1 + s2 + s3) / 3
IF(avg ≥ 60) { DISPLAY("pass") } ELSE { DISPLAY("fail") }
This combines two building blocks: first the average (add the three scores, divide by 3), then a comparison (is the average >= 60?). Compute the average into its own variable, then test it.

Problem 4 of 4

Modify + build — MIN of three. Starting from the find-max idea, write an algorithm that prints the smallest of three scores: 88, 72, 95.

Expected output: 72

Show AP pseudocode reference
a ← 88
b ← 72
c ← 95
smallest ← a
IF(b < smallest) { smallest ← b }
IF(c < smallest) { smallest ← c }
DISPLAY(smallest)
Take the two-number min and extend it: assume the first is smallest, then compare it against each other value with <, updating smallest whenever you find a lower one. This is the max building block modified (> became <) and extended to three.

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]