AP CSP Day 57: Web Protocols

Big Idea 3: Algorithms & Programming
Cycle 2 • Day 57 Practice • Hard Difficulty
Focus: List Traversal & Filtering

Practice Question

What is displayed after the following code runs?

temps ← [72, 85, 68, 91, 77, 83, 69]
hotDays ← 0
mildDays ← 0
FOR EACH t IN temps
{
   IF t ≥ 80
   {
      hotDays ← hotDays + 1
   }
   ELSE
   {
      IF t ≥ 70
      {
         mildDays ← mildDays + 1
      }
   }
}
DISPLAY(hotDays)
DISPLAY(mildDays)
Why This Answer?

Trace each temperature: 72 (<80, ≥70: mild), 85 (≥80: hot), 68 (<80, <70: neither), 91 (≥80: hot), 77 (<80, ≥70: mild), 83 (≥80: hot), 69 (<80, <70: neither). Hot=3, Mild=2.

Why Not the Others?

B) Only 2 temperatures fall in the mild range (70-79), not 4. C) Three temperatures are ≥80, not two. A) The counts are 3 and 2, not 4 and 3.

Common Mistake
Watch Out!

Students count temperatures ≥70 for mildDays without first checking if they are ≥80 (which would route to hotDays instead). In an IF/ELSE, temperatures ≥80 go to hot and never reach the mild check.

AP Exam Tip

In nested IF/ELSE structures, elements that satisfy the outer condition never reach the inner condition. Track each element through the exact path it takes in the conditional logic.

Keep Practicing!

Consistent daily practice is the key to AP CSP success.

AP CSP Resources Get 1-on-1 Help
Back to blog

Leave a comment

Please note, comments need to be approved before they are published.