AP CSP Day 25: Accumulator Pattern
Share
Practice Question
What is displayed after the following code runs?
temp ← 72
IF temp > 80
{
DISPLAY("hot")
}
IF temp > 60
{
DISPLAY("warm")
}
IF temp > 40
{
DISPLAY("cool")
}These are three separate IF statements (not IF/ELSE), so each one is evaluated independently. With temp = 72: 72 > 80 is false (skip), 72 > 60 is true (display "warm"), 72 > 40 is true (display "cool"). Both "warm" and "cool" are displayed.
A) 72 is not greater than 80, so "hot" is not displayed. B) The third IF statement also evaluates to true, so "cool" is displayed too. D) The first condition is false, so "hot" is not included.
Students treat separate IF statements as an IF/ELSE chain, thinking that once one condition is true, the rest are skipped. Separate IF statements each evaluate independently.
Critical distinction: separate IF statements all evaluate independently. IF/ELSE chains stop at the first true condition. Look for ELSE to determine which pattern is being used.
Keep Practicing!
Consistent daily practice is the key to AP CSP success.
AP CSP Resources Get 1-on-1 Help