- Which of the following code segments will output "Pass" if the variable score is greater than or equal to 70, and "Fail" otherwise?
Answer: IF(score >= 70)
{
DISPLAY("Pass")
}
ELSE
{
DISPLAY("Fail")
}
Choice A correctly uses the >= operator to check if score is greater than or equal to 70, which matches the requirement. Choice B uses > which would exclude exactly 70. Choice C uses = which only checks for equality to 70. Choice D uses <= which would display "Pass" for scores 70 and below, which is the opposite of what's needed.
- In the following code segment, under what condition will "Grade A" be displayed?
IF(score >= 90)
{
DISPLAY("Grade A")
}
IF(score >= 80)
{
DISPLAY("Grade B")
}
IF(score >= 70)
{
DISPLAY("Grade C")
}
Answer: When score is 90 or higher
"Grade A" will be displayed when score >= 90, which means score is 90 or higher. Note that this code structure allows multiple grades to be displayed for the same score. Choice A is incorrect because >= includes all values 90 and above. Choices C and D describe conditions for other grade displays but not specifically for "Grade A".
- Which of the following Boolean expressions is equivalent to the condition used in this IF statement?
IF(NOT(age < 18))
{
DISPLAY("Can vote")
}
Answer: age >= 18
NOT(age < 18) is equivalent to age >= 18. When age < 18 is false, it means age is not less than 18, which is the same as age >= 18. Choice A excludes age = 18. Choice C only includes age = 18. Choice D represents age <= 18, which is the opposite condition.
- Based on the code snippet, a grading system uses: IF score>=90 grade="A" ELSE IF score>=70 grade="C" ELSE grade="F". How would you modify the condition to award "B" for 80≤score<90?
Answer: Insert ELSE IF score>=80 grade="B" before score>=70.
This question tests understanding of conditionals in AP Computer Science Principles, specifically how to modify existing conditional structures to add new logic branches. When adding conditions to an existing IF-ELSE IF chain, placement and order are crucial because conditions are evaluated sequentially. Choice A is correct because inserting "ELSE IF score>=80 grade="B"" between the existing conditions properly handles the range 80≤score<90 - scores of 90+ still get "A", scores 80-89 get "B", and the existing logic for "C" and "F" remains intact. Choice B is incorrect because changing to score>80 would exclude score=80 from getting an "A", leaving it to fall through to "C". To help students: Draw number lines showing grade ranges and emphasize that ELSE IF conditions must be ordered from most restrictive to least restrictive. Practice modifying existing code rather than just writing from scratch.
- Which of the following Boolean expressions would be used in a conditional statement to check if a number is between 10 and 20, inclusive?
Answer: (number >= 10) AND (number <= 20)
Choice B correctly uses AND with >= and <= to include both 10 and 20 in the range. Choice A excludes the endpoints 10 and 20 using > and <. Choice C uses OR which would be true for almost all numbers (any number less than 20 OR greater than 10). Choice D also uses OR incorrectly and would be true for most numbers.
- What will be the result of executing this code when num = 15?
IF(num MOD 2 = 0)
{
DISPLAY("Even")
}
ELSE
{
IF(num MOD 5 = 0)
{
DISPLAY("Multiple of 5")
}
ELSE
{
DISPLAY("Odd")
}
}
Answer: Multiple of 5
When num = 15, first we check if 15 MOD 2 = 0. Since 15 MOD 2 = 1, this is false, so we go to the ELSE block. In the nested IF, we check if 15 MOD 5 = 0. Since 15 MOD 5 = 0, this is true, so "Multiple of 5" is displayed. Choice A is incorrect because 15 is odd. Choice C is incorrect because we don't reach that ELSE. Choice D is incorrect because only one path executes.
- What will be displayed by the following code when x = 10?
IF(x > 5)
{
DISPLAY("Large")
IF(x > 15)
{
DISPLAY(" and Very Large")
}
}
ELSE
{
DISPLAY("Small")
}
Answer: Large
When x = 10, the condition (x > 5) is true since 10 > 5, so we enter the IF block and display "Large". Then we check the nested condition (x > 15), which is false since 10 is not > 15, so " and Very Large" is not displayed. Choice B is incorrect because the nested condition is false. Choice C is incorrect because x > 5. Choice D is incorrect because only "Large" is displayed.
- In the given scenario, an online store uses: IF isPremium==true OR cartTotal>=100 discount=0.20 ELSE discount=0.00. Which branch of the condition will execute if isPremium is false and cartTotal is 120?
Answer: The IF branch executes; discount becomes 0.20.
This question tests understanding of conditionals in AP Computer Science Principles, specifically how the OR logical operator works in compound conditions. The OR operator makes a condition true if at least one of its parts is true, allowing multiple paths to the same outcome. Choice A is correct because even though isPremium is false, cartTotal (120) is greater than or equal to 100, making the overall condition true due to the OR operator, so the IF branch executes and discount becomes 0.20. Choice D is incorrect because it misunderstands how OR works - any true condition makes the whole expression true. To help students: Use truth tables for OR operations and practice evaluating compound conditions step by step. Emphasize that OR needs only one true condition, while AND needs all conditions true.
- In the given scenario, an online store applies discounts using this pseudo-code: IF membershipLevel == "premium" THEN finalPrice = price * 0.80 ELSE finalPrice = price. Which branch of the condition will execute if membershipLevel is "premium"?
Answer: The IF branch executes; 20% discount applies.
This question tests understanding of conditionals in AP Computer Science Principles, specifically how logical branches determine program flow. Conditionals allow programs to execute different actions based on whether a condition is true or false. They use 'if', 'else if', and 'else' statements to control flow. Choice C is correct because when membershipLevel equals "premium", the condition in the IF statement evaluates to true, causing the IF branch to execute and apply the 20% discount (finalPrice = price * 0.80). Choice A is incorrect because it assumes the ELSE branch runs when the condition is true, which shows a fundamental misunderstanding of how IF-ELSE logic works. To help students: Use flowcharts to visualize the decision path and trace through examples with specific values. Emphasize that only one branch executes in an IF-ELSE structure - never both.
- In the given scenario, a security system uses: IF motionDetected==true alarm="ON" ELSE alarm="OFF". Which branch of the condition will execute if motionDetected is false?
Answer: The ELSE branch executes; alarm becomes "OFF".
This question tests understanding of conditionals in AP Computer Science Principles, specifically how boolean conditions determine which branch executes. Conditionals evaluate boolean expressions (true/false) and execute the corresponding branch based on the result. Choice B is correct because when motionDetected is false, the condition (motionDetected==true) evaluates to false, causing the ELSE branch to execute and set alarm to "OFF". Choice C is incorrect because it suggests both branches can execute, but in an IF-ELSE structure, exactly one branch runs - never both. To help students: Clarify that IF-ELSE is mutually exclusive and use state diagrams to show how the system responds to different inputs. Practice with boolean variables to reinforce true/false logic.
- What will be the output of the following code segment when age is 16?
IF(age >= 18)
{
DISPLAY("Adult")
}
ELSE
{
DISPLAY("Minor")
}
Answer: Minor
When age is 16, the condition (age >= 18) evaluates to false since 16 is not greater than or equal to 18. Therefore, the ELSE block executes, displaying "Minor". Choice A is incorrect because the condition is false. Choice C is incorrect because only one block executes in an IF-ELSE statement. Choice D is incorrect because the ELSE block will execute.
- Based on the code snippet for a traffic light: IF lightColor=="green" action="go" ELSE action="stop". What is the output when lightColor is "red"?
Answer: action becomes "stop" because the ELSE runs.
This question tests understanding of conditionals in AP Computer Science Principles, specifically how simple IF-ELSE structures handle non-matching conditions. Conditionals with IF-ELSE have exactly two paths: one for when the condition is true and one for all other cases. Choice B is correct because when lightColor is "red", it doesn't equal "green", so the condition is false and the ELSE branch executes, setting action to "stop". Choice A is incorrect because it misunderstands that ELSE handles all cases where the IF condition is false, not just unchecked cases. To help students: Use truth tables to show all possible outcomes and emphasize that IF-ELSE is exhaustive - one branch always executes. Practice with different values to reinforce that ELSE catches everything the IF doesn't.
- Which of the following represents a valid conditional statement structure in the AP Computer Science Principles reference sheet notation?
Answer: IF(condition)
{
block of statements
}
ELSE
{
block of statements
}
Choice B uses the correct IF-ELSE syntax as specified in the AP Computer Science Principles reference sheet. Choices A, C, and D use non-standard keywords (WHEN/OTHERWISE, CHECK/ALTERNATE, CONDITION/FALSE) that are not part of the official AP CSP notation.
- What will be displayed by the following code when x = 5 and y = 10?
IF(x > y)
{
DISPLAY("x is greater")
}
ELSE
{
IF(x < y)
{
DISPLAY("y is greater")
}
ELSE
{
DISPLAY("equal")
}
}
Answer: y is greater
With x = 5 and y = 10, the first condition (x > y) is false, so the ELSE block executes. In the nested IF, the condition (x < y) is true since 5 < 10, so "y is greater" is displayed. Choice A is incorrect because 5 is not greater than 10. Choice C is incorrect because the values are not equal. Choice D is incorrect because the nested IF condition is true.
- Based on the code snippet for student grading: IF score >= 90 grade="A" ELSE IF score >= 80 grade="B" ELSE grade="C". What is the output when score is 89?
Answer: grade becomes "B" because 89≥80.
This question tests understanding of conditionals in AP Computer Science Principles, specifically how cascading IF-ELSE IF statements evaluate conditions sequentially. Conditionals check each condition in order and execute the first branch where the condition is true, then skip remaining conditions. Choice B is correct because when score is 89, the first condition (score >= 90) is false, but the second condition (score >= 80) is true, so grade becomes "B". Choice A is incorrect because it assumes rounding or approximation, which doesn't happen in conditional logic - 89 is strictly less than 90. To help students: Practice tracing through each condition step-by-step and emphasize that conditions are checked in order. Use number lines to visualize boundary values and teach students to test edge cases like 89, 90, and 80. - Based on the code snippet for student grading: IF score > 90 grade="A" ELSE IF score >= 80 grade="B" ELSE grade="C". What is the output when score is 90?
Answer: grade becomes "B" because 90 is not >90.
This question tests understanding of conditionals in AP Computer Science Principles, specifically the critical difference between > (greater than) and >= (greater than or equal to) operators. Conditionals evaluate conditions precisely as written, and boundary values often reveal student understanding of comparison operators. Choice B is correct because when score is 90, the first condition (score > 90) is false since 90 is not greater than 90, but the second condition (score >= 80) is true, so grade becomes "B". Choice A is incorrect because it confuses > with >=, a common error when students don't pay attention to boundary conditions. To help students: Use number lines to visualize the difference between > and >= operators. Create exercises specifically testing boundary values and emphasize reading operators carefully. - Based on the code snippet, a weather app uses: IF temperature>75 AND weather=="sunny" suggest="beach" ELSE suggest="cafe". Which branch of the condition will execute if temperature is 80 and weather is "cloudy"?
Answer: The ELSE branch executes; it suggests "cafe".
This question tests understanding of conditionals in AP Computer Science Principles, specifically how the AND logical operator requires all conditions to be true. The AND operator creates a compound condition that is only true when every individual condition is satisfied. Choice B is correct because although temperature (80) is greater than 75, weather is "cloudy" not "sunny", so the overall condition is false (true AND false = false), causing the ELSE branch to execute and suggest "cafe". Choice C is incorrect because it assumes one true condition is sufficient, confusing AND with OR logic. To help students: Create truth tables showing AND requires all conditions true and use real-world analogies like "you need money AND time to go on vacation". Practice tracing compound conditions with mixed true/false values.
- In the given scenario, a weather app uses: IF weatherCondition=="sunny" suggest="park" ELSE IF weatherCondition=="rainy" suggest="museum" ELSE suggest="stay home". What will happen if weatherCondition is "cloudy"?
Answer: It suggests "stay home" using the ELSE branch.
This question tests understanding of conditionals in AP Computer Science Principles, specifically how ELSE clauses handle cases when no previous conditions match. Conditionals evaluate each condition sequentially, and the ELSE clause serves as a catch-all for any input not matching previous conditions. Choice C is correct because when weatherCondition is "cloudy", it doesn't match "sunny" or "rainy", so the program executes the ELSE branch and suggests "stay home". Choice B is incorrect because it assumes the program makes inferences about weather relationships, but conditionals only check exact matches. To help students: Emphasize that string comparisons require exact matches and that ELSE handles all unspecified cases. Create exercises with various inputs to show how ELSE acts as a default option.
- Which of the following code segments will display "Pass" only when BOTH test1 and test2 scores are greater than 70?
Answer: IF(test1 > 70)
{
IF(test2 > 70)
{
DISPLAY("Pass")
}
}
Choice A uses nested IF statements which ensures both conditions must be true - test1 > 70 AND test2 > 70. Choice B uses OR, which would display "Pass" if either test is above 70. Choice C uses separate IF statements that could display "Pass" twice or once depending on the scores. Choice D requires test1 > 70 but test2 <= 70, which is not what we want.
- In the given scenario, a traffic light uses: IF light=="green" action="go" ELSE IF light=="yellow" action="slow" ELSE action="stop". What will happen if light is "yellow"?
Answer: It sets action to "slow" from the ELSE IF.
This question tests understanding of conditionals in AP Computer Science Principles, specifically how cascading IF-ELSE IF-ELSE structures evaluate conditions in sequence. When multiple conditions exist, the program checks each in order and executes the first matching branch, then skips the rest. Choice C is correct because when light is "yellow", the first condition (light=="green") is false, but the second condition (light=="yellow") is true, so action becomes "slow" and the final ELSE is never reached. Choice B is incorrect because it assumes the program jumps to ELSE without checking intermediate conditions. To help students: Use flowcharts to trace the path through multiple conditions and emphasize that execution stops after the first true condition. Practice with various inputs to show how order matters in ELSE IF chains.