AP CSP Topic 3.6 Coding Practice - Conditionals

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

Conditionals — 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 the Gate and Write the Rule, hand-tracing which branch runs. Now type and run the same gate scenario for real — the problems get harder as you go, from a single IF to an IF-ELSE with a computed condition, ending with one you build from scratch. Evaluate the condition first, predict the output, then check yourself, hardest last.

Problem 1 of 4

A rider is 52 inches tall. Write an IF that displays exactly Board the ride when height is at least 48. (For 52, it should print.)

Expected output: Board the ride

Show AP pseudocode reference
height ← 52
IF(height ≥ 48)
{
  DISPLAY("Board the ride")
}
Use >= for 'at least': the condition height >= 48 is true for 52, so the block runs. Put the print inside the IF so it only runs when the condition is true.

Problem 2 of 4

A rider is 45 inches tall. Write an IF-ELSE: display Board the ride when height is at least 48, otherwise display Grow a bit more. (For 45, it should print the second message.)

Expected output: Grow a bit more

Show AP pseudocode reference
height ← 45
IF(height ≥ 48)
{
  DISPLAY("Board the ride")
}
ELSE
{
  DISPLAY("Grow a bit more")
}
Evaluate the condition first: 45 >= 48 is false, so the ELSE block runs. The ELSE has no condition of its own — it catches every case the IF did not make true.

Problem 3 of 4

A group ticket costs 12 dollars per person for a group of 4. Compute the total, then display Group discount applies when the total is at least 40, otherwise display No discount.

Expected output: Group discount applies

Show AP pseudocode reference
pricePerPerson ← 12
groupSize ← 4
total ← pricePerPerson * groupSize
IF(total ≥ 40)
{
  DISPLAY("Group discount applies")
}
ELSE
{
  DISPLAY("No discount")
}
First do the arithmetic: total = 12 * 4 = 48. Then the condition total >= 40 is true, so the IF block runs. A condition can be a computed value, not just a bare variable.

Problem 4 of 4

Build from scratch: a rider is 47 inches tall. First display Welcome! on its own line, then use an IF-ELSE to display Board the ride when height is at least 48, otherwise Grow a bit more. Two lines of output.

Expected output: Welcome! Grow a bit more

Show AP pseudocode reference
height ← 47
DISPLAY("Welcome!")
IF(height ≥ 48)
{
  DISPLAY("Board the ride")
}
ELSE
{
  DISPLAY("Grow a bit more")
}
The greeting runs before the decision, so it prints every time. Then evaluate 47 >= 48: it is false, so the ELSE runs. Order matters — the sequential line prints first, then exactly one branch of the IF-ELSE.

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]