All questions
Question 1
Given this shopping-cart pseudo-code, what will the discount be if isMember=false, total=160, isSeasonSale=true?
// Inputs: isMember, total, isSeasonSale
IF isMember
IF total >= 100
IF isSeasonSale
discount = 0.20
ELSE
discount = 0.10
ELSE
discount = 0.05
ELSE
IF isSeasonSale AND total >= 150
discount = 0.15
ELSE
discount = 0.00
- 0.20
- 0.15 (correct answer)
- 0.10
- 0.00
Explanation: This question tests understanding of nested conditionals in AP Computer Science Principles, specifically evaluating how non-member paths execute. Nested conditionals allow programs to make complex decisions by checking conditions within conditions, creating different execution paths based on multiple criteria. In this scenario, with isMember=false, the code immediately branches to the ELSE block, bypassing all member-specific discounts and checking only non-member conditions. Choice B is correct because when isMember is false, total is 160 (>= 150), and isSeasonSale is true, the condition 'isSeasonSale AND total >= 150' evaluates to true, resulting in discount = 0.15. Choice C is incorrect because 0.10 is only available to members with total >= 100 when it's not a season sale. To help students: Draw flowcharts showing how false conditions immediately skip entire nested blocks, practice with concrete values to see which paths execute, and emphasize that AND requires both conditions to be true. Highlight that understanding which blocks are skipped is as important as knowing which execute.
Question 2
Given the conditions in the pseudo-code, what will the output be if timeOfDay="day", traffic="high", hasPedestrian=true?
// Inputs: timeOfDay, traffic, hasPedestrian
IF timeOfDay == "night"
PRINT "FLASHING"
ELSE
IF traffic == "high"
PRINT "GREEN"
ELSE
IF hasPedestrian
PRINT "WALK"
ELSE
PRINT "RED"
- WALK
- RED
- GREEN (correct answer)
- FLASHING
Explanation: This question tests understanding of nested conditionals in AP Computer Science Principles, focusing on how early conditions can override later ones in the decision tree. Nested conditionals evaluate conditions in order, and once a condition is met and an action is taken, subsequent conditions in that branch are not evaluated. The traffic light code first checks time of day, then traffic levels, with pedestrian considerations only relevant in specific circumstances. Choice C is correct because with timeOfDay="day" (not night) and traffic="high", the code prints "GREEN" immediately after the traffic check, never reaching the hasPedestrian condition. Choice A is incorrect because "WALK" would require traffic to NOT be "high", but here traffic is explicitly "high", causing an earlier exit. To help students: Demonstrate that the order of conditions matters, show how some inputs make certain code sections unreachable, and use flowcharts with highlighted paths. Emphasize that in nested conditionals, the first matching condition "wins" and prevents further evaluation in that branch.
Question 3
Which sequence of conditions must be met for the traffic light to set signal="WALK"?
// Inputs: hasPedestrian, timeOfDay, traffic
IF timeOfDay == "night"
signal = "FLASHING"
ELSE
IF traffic == "high"
signal = "GREEN"
ELSE
IF hasPedestrian
signal = "WALK"
ELSE
signal = "RED"
- night and hasPedestrian true
- not night, traffic not high, hasPedestrian true (correct answer)
- not night, traffic high, hasPedestrian true
- night and traffic not high
Explanation: This question tests understanding of nested conditionals in AP Computer Science Principles, specifically identifying the exact path through multiple decision points. Nested conditionals create branching logic where reaching certain outcomes requires specific combinations of conditions. The traffic light system first checks time of day, then traffic levels, and finally pedestrian presence to determine the appropriate signal. Choice B is correct because signal="WALK" only occurs when: timeOfDay is NOT "night" (to pass the first condition), traffic is NOT "high" (to reach the inner ELSE), and hasPedestrian is true (to trigger the WALK signal). Choice C is incorrect because if traffic is "high", the signal would be set to "GREEN" immediately, never reaching the pedestrian check. To help students: Work backwards from the desired outcome, identify all conditions that must be true or false, and use process of elimination. Teach students to recognize that ELSE branches represent the negation of the IF condition, making "not night" and "traffic not high" necessary conditions.
Question 4
In this shopping cart code, which conditions must be met for a 20% discount?
// Online Shopping Cart discount rules
IF isMember
IF total >= 100
IF isSeasonalSale
discount = 20
ELSE
discount = 15
ELSE
discount = 5
ELSE
IF total >= 150
IF isSeasonalSale
discount = 10
ELSE
discount = 0
ELSE
discount = 0
- Not a member, total >= 150, seasonal sale
- Member, total >= 100, seasonal sale (correct answer)
- Member, total < 100, seasonal sale
- Not a member, total >= 150, not seasonal
Explanation: This question tests understanding of nested conditionals in AP Computer Science Principles, focusing on tracing through multiple decision layers to identify specific outcomes. Nested conditionals create a hierarchical decision structure where inner conditions are only evaluated if outer conditions are met. In this shopping cart code, the program first checks membership status, then purchase amount, and finally seasonal sale status to determine the appropriate discount. Choice B is correct because a 20% discount requires three specific conditions: the customer must be a member (first IF), their total must be at least $100 (second IF), and it must be a seasonal sale (third IF). Choice A is incorrect because non-members cannot receive a 20% discount regardless of other conditions, as this discount is nested within the member branch. To help students master this concept, encourage them to trace through each path systematically using a decision tree diagram, highlighting which conditions must be true at each level. Remind students that in nested structures, all parent conditions must be satisfied before inner conditions are even evaluated.
Question 5
If isMember is true and total is 99 during seasonal sale, what is the discount?
// Online Shopping Cart discount rules
IF isMember
IF total >= 100
IF isSeasonalSale
discount = 20
ELSE
discount = 15
ELSE
discount = 5
ELSE
IF total >= 150
IF isSeasonalSale
discount = 10
ELSE
discount = 0
ELSE
discount = 0
- 5% (correct answer)
- 15%
- 20%
- 0%
Explanation: This question tests understanding of nested conditionals in AP Computer Science Principles, focusing on how inner conditions are bypassed when outer conditions fail. Nested conditionals create decision trees where each level depends on the previous level's outcome, allowing for precise control flow based on multiple criteria. In this scenario, the code checks membership status (true), then evaluates if the total meets the 100threshold(falsesince99<100),whichdirectsexecutiontotheinnerELSEbranch.ChoiceAiscorrectbecausewhenisMemberistruebuttotal<100,thecodefollowsthepath:IFisMember(true)→IFtotal>=100(false)→ELSE→discount=5,regardlessofseasonalsalestatus.ChoiceCisincorrectbecauseeventhoughit′saseasonalsale,the20100, which isn't met. To help students grasp this concept, demonstrate how failing an outer condition prevents access to deeper nested benefits, similar to how you can't enter a VIP room's special area without first entering the VIP room itself. Practice with boundary cases like this (99 vs 100) helps students understand the importance of precise condition checking.
Question 6
Which sequence of conditions must be met for a 5% discount?
// Online Shopping Cart discount rules
IF isMember
IF total >= 100
IF isSeasonalSale
discount = 20
ELSE
discount = 15
ELSE
discount = 5
ELSE
IF total >= 150
IF isSeasonalSale
discount = 10
ELSE
discount = 0
ELSE
discount = 0
- Not a member, total < 150
- Member, total < 100 (correct answer)
- Member, total >= 100, seasonal
- Not a member, total >= 150, seasonal
Explanation: This question tests understanding of nested conditionals in AP Computer Science Principles, requiring students to identify the specific conditions that lead to a 5% discount. Nested conditionals create a decision tree where each branch represents a different scenario, and understanding these paths is essential for program comprehension. In this code, a 5% discount occurs in exactly one scenario: when a customer is a member but their total purchase is less than $100. Choice B is correct because it describes the path: IF isMember (true) → IF total >= 100 (false) → ELSE → discount = 5, and this discount applies regardless of seasonal sale status. Choice A is incorrect because non-members with total < 150 receive 0% discount, not 5%. To help students master this concept, create visual representations showing how each discount percentage can only be reached through one specific path. Emphasize that the 5% discount is a consolation prize for members who don't meet the spending threshold, encouraging loyalty even for smaller purchases.
Question 7
If isMember=true and isSeasonSale=true are true, what is the discount when total=99?
// Inputs: isMember, total, isSeasonSale
IF isMember
IF total >= 100
IF isSeasonSale
discount = 0.20
ELSE
discount = 0.10
ELSE
discount = 0.05
ELSE
IF isSeasonSale AND total >= 150
discount = 0.15
ELSE
discount = 0.00
- 0.20
- 0.10
- 0.05 (correct answer)
- 0.15
Explanation: This question tests understanding of nested conditionals in AP Computer Science Principles, demonstrating how failing an intermediate condition bypasses deeper nested checks. Nested conditionals create a hierarchy where inner conditions are only evaluated if all outer conditions pass, making the order and structure crucial for determining outcomes. In this scenario, while the customer is a member (passing the first check), the total of 99 fails the second condition (total >= 100), preventing access to the innermost seasonal discount logic. Choice C is correct because when isMember is true but total is 99 (< 100), the code executes the ELSE block of the second IF statement, setting discount = 0.05, and never evaluates the isSeasonSale condition at all. Choice A is incorrect because 0.20 requires total >= 100 to even reach the seasonal check, which isn't satisfied with total=99. To help students: Use step-by-step tracing with boxes around each conditional level, practice identifying which conditions are 'gatekeepers' to inner logic, and create test cases at boundaries. Emphasize that in nested structures, you must pass each level to reach the next, like unlocking doors in sequence.
Question 8
Identify the error in the nested conditionals that prevents "Severe Storm" from printing.
// Inputs: isThunderstorm, wind
IF isThunderstorm
IF wind <= 30
PRINT "Severe Storm"
ELSE
PRINT "Storm"
ELSE
PRINT "No Alert"
- The wind check should use wind >= 30 (correct answer)
- The outer IF should check wind, not isThunderstorm
- The ELSE should print "Heat Advisory"
- The code needs a loop to repeat checks
Explanation: This question tests understanding of nested conditionals in AP Computer Science Principles, focusing on debugging logical errors in condition statements. Nested conditionals require careful attention to comparison operators and logical flow to ensure desired outcomes are achievable. The code attempts to categorize storm severity based on wind speed, but contains a logical error preventing the intended output. Choice A is correct because the condition "wind <= 30" means "Severe Storm" only prints when wind is 30 or LESS during a thunderstorm, which is backwards - severe storms should have HIGH winds, so it should be "wind >= 30". Choice B is incorrect because checking wind first would change the entire logic structure and wouldn't specifically fix the severe storm categorization issue. To help students: Teach them to verify that conditions match real-world logic, use test cases with boundary values, and check that all desired outputs are actually reachable. Emphasize the importance of using the correct comparison operators (<, >, <=, >=) to match the intended logic.
Question 9
What condition would cause the code to follow the alternative path and print "NoDeal"?
// Inputs: isMember, total
IF isMember
IF total >= 50
PRINT "MemberDiscount"
ELSE
PRINT "Member"
ELSE
IF total >= 150
PRINT "GuestDiscount"
ELSE
PRINT "NoDeal"
- isMember true and total < 50
- isMember false and total < 150 (correct answer)
- isMember false and total >= 150
- isMember true and total >= 50
Explanation: This question tests understanding of nested conditionals in AP Computer Science Principles, specifically identifying conditions that lead to specific outputs. Nested conditionals create multiple pathways through code, and understanding which conditions lead to which outcomes is crucial for debugging and design. The code structure shows two main branches based on membership status, with further decisions based on purchase totals. Choice B is correct because "NoDeal" prints when isMember is false (taking the ELSE path) AND total < 150 (failing the nested condition), which describes a non-member with insufficient purchase amount. Choice A is incorrect because if isMember is true, the code would print either "MemberDiscount" or "Member", never reaching the "NoDeal" option. To help students: Create truth tables showing all possible combinations, highlight the specific path that leads to each output, and practice reverse engineering - starting from the output and working backwards. Remind students that understanding the "alternative path" means following the ELSE branches through the nested structure.
Question 10
Given this game-action pseudo-code, what will the action be if health=40, hasPotion=true, enemyNear=true, hasSpecial=false?
// Inputs: health, hasPotion, enemyNear, hasSpecial
IF enemyNear
IF health < 30
IF hasPotion
action = "HEAL"
ELSE
action = "RUN"
ELSE
IF hasSpecial
action = "SPECIAL"
ELSE
action = "ATTACK"
ELSE
action = "EXPLORE"
- HEAL
- RUN
- ATTACK (correct answer)
- EXPLORE
Explanation: This question tests understanding of nested conditionals in AP Computer Science Principles, focusing on game logic decision-making with multiple factors. Nested conditionals enable complex game AI by evaluating threat levels, resources, and capabilities in a hierarchical manner. The code first checks if an enemy is near, then evaluates health status, and finally considers available actions based on resources. Choice C is correct because with enemyNear=true and health=40 (which is >= 30), the code enters the ELSE branch of the health check, then with hasSpecial=false, it defaults to "ATTACK". Choice A would be incorrect because "HEAL" only occurs when health < 30 AND hasPotion is true, but here health=40 exceeds the threshold. To help students: Create decision trees showing all possible paths, test edge cases like health exactly at 30, and trace through with colored pencils to highlight the actual path taken. Emphasize that game logic often involves checking the most critical conditions first (like enemy presence) before considering other factors.
Question 11
In this shopping-cart pseudo-code, which conditions must be met for message "VIP+Season" to print?
// Inputs: isMember, total, isSeasonSale
IF isMember
IF total >= 100
IF isSeasonSale
PRINT "VIP+Season"
ELSE
PRINT "VIP"
ELSE
PRINT "Member"
ELSE
IF total >= 150
IF isSeasonSale
PRINT "Guest+Season"
ELSE
PRINT "Guest"
ELSE
PRINT "NoDeal"
- isMember true, total >= 100, isSeasonSale true (correct answer)
- isMember true, total > 100, isSeasonSale false
- isMember false, total >= 100, isSeasonSale true
- isMember true, total >= 150, isSeasonSale true
Explanation: This question tests understanding of nested conditionals in AP Computer Science Principles, focusing on how multiple conditions must be satisfied in sequence. Nested conditionals create a decision tree where each inner condition is only evaluated if the outer condition is true. In this shopping cart scenario, the code checks three levels of conditions: membership status, purchase total, and seasonal sale status. Choice A is correct because to print "VIP+Season", the code must first check if isMember is true, then verify total >= 100, and finally confirm isSeasonSale is true - all three conditions must be met in this exact sequence. Choice D is incorrect because it requires total >= 150, which would actually prevent the code from entering the correct branch since the condition checks for >= 100, not >= 150. To help students: Use indentation to visualize nesting levels, trace through each path systematically, and create test cases for different combinations. Emphasize that in nested conditionals, the order matters - inner conditions are only evaluated when outer conditions are true.
Question 12
If score=89, participation=true, attendance=92, what is the finalGrade?
// Start with letter grade from score
IF score >= 90
grade = "A"
ELSE
IF score >= 80
grade = "B"
ELSE
grade = "C"
// Adjust for class habits
IF grade == "B"
IF participation == false
grade = "C"
ELSE
IF attendance < 90
grade = "C"
finalGrade = grade
- A
- B (correct answer)
- C
- No grade assigned
Explanation: This question tests understanding of nested conditionals in AP Computer Science Principles, focusing on how variable values can be modified through conditional logic. Nested conditionals here demonstrate a two-phase process: first assigning a base grade, then potentially adjusting it based on additional criteria. The code initially assigns grade "B" because score=89 falls in the 80-89 range, then checks if this B grade should be downgraded based on participation and attendance. Choice B is correct because with participation=true and attendance=92 (which is >= 90), neither condition for downgrading the B to C is met, so the final grade remains "B". Choice C would be incorrect because it assumes the grade gets downgraded, but both participation is true (not false) and attendance exceeds 90%. To help students: Trace variable values at each step, understand that conditions can modify previously assigned values, and practice with different input combinations. Emphasize the importance of understanding when conditions are NOT met, as this determines which code blocks are skipped.
Question 13
If score=79 and attendance=95 are true, what is the result?
// Inputs: score, attendance
IF score >= 80
grade = "B"
IF attendance < 90
grade = "C"
ELSE
grade = "C"
PRINT grade
- B
- C (correct answer)
- A
- No output
Explanation: This question tests understanding of nested conditionals in AP Computer Science Principles, focusing on how conditions control code execution paths. Nested conditionals can have inner conditions that are never evaluated if the outer condition fails, which is a key concept for understanding program flow. In this grading scenario, the code first checks if score >= 80, and since score=79, this condition is false, causing the program to skip the entire nested block and jump to the ELSE clause. Choice B is correct because with score=79 (less than 80), the code immediately goes to the ELSE block and assigns grade = "C", never checking the attendance condition. Choice A is incorrect because grade "B" is only assigned when score >= 80, which is not satisfied here. To help students: Use step-by-step execution traces, emphasize that failing an outer condition means all nested conditions are ignored, and practice with values just above and below boundary conditions. Teach students to identify "unreachable code" - conditions that won't be evaluated based on the input values.
Question 14
Which sequence of conditions must be met for action="SPECIAL" to occur?
// Inputs: enemyNear, health, hasSpecial
IF enemyNear
IF health < 30
action = "RUN"
ELSE
IF hasSpecial
action = "SPECIAL"
ELSE
action = "ATTACK"
ELSE
action = "EXPLORE"
- enemyNear false and hasSpecial true
- enemyNear true and health < 30
- enemyNear true, health >= 30, hasSpecial true (correct answer)
- enemyNear true, health >= 30, hasSpecial false
Explanation: This question tests understanding of nested conditionals in AP Computer Science Principles, focusing on tracing the exact conditions needed for a specific outcome. Nested conditionals create a hierarchy of decisions where inner conditions are only evaluated if outer conditions are satisfied first. The game logic checks enemy proximity first, then health levels, and finally special ability availability to determine the appropriate action. Choice C is correct because action="SPECIAL" requires three specific conditions in sequence: enemyNear must be true (to enter the first IF), health must be >= 30 (to reach the ELSE branch of the health check), and hasSpecial must be true (to select SPECIAL over ATTACK). Choice D is incorrect because if hasSpecial is false, the action would be "ATTACK", not "SPECIAL". To help students: Create a checklist of required conditions for each outcome, practice backward reasoning from output to input requirements, and use truth tables to verify all paths. Remind students that for deeply nested outcomes, ALL parent conditions must align correctly to reach the desired result.
Question 15
Given this weather-alert pseudo-code, what will the output be if temp=95, humidity=70, wind=10, isThunderstorm=false?
// Inputs: temp, humidity, wind, isThunderstorm
IF temp >= 90
IF humidity >= 60
PRINT "Heat Advisory"
ELSE
IF wind >= 25
PRINT "Wind Alert"
ELSE
PRINT "No Alert"
ELSE
IF isThunderstorm
IF wind >= 30
PRINT "Severe Storm"
ELSE
PRINT "Storm"
ELSE
PRINT "No Alert"
- Wind Alert
- Heat Advisory (correct answer)
- Storm
- No Alert
Explanation: This question tests understanding of nested conditionals in AP Computer Science Principles, specifically evaluating multiple weather conditions to determine appropriate alerts. Nested conditionals allow programs to make complex decisions by checking conditions within conditions, creating sophisticated logic paths. The weather alert system first checks if temperature >= 90, and since temp=95, this condition is true, leading to the nested check for humidity >= 60. Choice B is correct because with temp=95 and humidity=70, both conditions are satisfied, resulting in "Heat Advisory" being printed - the code never reaches the wind or thunderstorm checks. Choice A is incorrect because "Wind Alert" would only print if temp >= 90, humidity < 60, AND wind >= 25, but here humidity is 70 (>= 60), so the code takes a different path. To help students: Draw flowcharts showing each decision point, use actual values to trace through the logic step-by-step, and highlight which branches are never reached. Remind students that once a condition is met and an action is taken, the remaining ELSE branches are skipped entirely.
Question 16
What condition would cause the code to follow the 0.00 discount path?
// Inputs: isMember, total, isSeasonSale
IF isMember
IF total >= 100
IF isSeasonSale
discount = 0.20
ELSE
discount = 0.10
ELSE
discount = 0.05
ELSE
IF isSeasonSale AND total >= 150
discount = 0.15
ELSE
discount = 0.00
- Not a member and (not season sale or total < 150) (correct answer)
- Member and total < 100 and season sale
- Member and total >= 100 and season sale
- Not a member and season sale and total >= 100
Explanation: This question tests understanding of nested conditionals in AP Computer Science Principles, focusing on identifying conditions that lead to specific outcomes. Nested conditionals create multiple execution paths, and understanding which combinations lead to each outcome requires careful logical analysis. In this scenario, the 0.00 discount only occurs in the outermost ELSE block when the customer is not a member AND the nested condition fails. Choice A is correct because discount = 0.00 occurs when isMember is false (entering the outer ELSE) AND either isSeasonSale is false OR total < 150, which can be expressed as 'not a member and (not season sale or total < 150)' using logical operators. Choice D is incorrect because if total >= 100 (not 150), a non-member during a season sale would still get 0.00 discount since the threshold for non-members is 150. To help students: Practice converting code paths to logical expressions, use truth tables to verify complex conditions, and work backwards from outcomes to determine required inputs. Emphasize the importance of understanding both positive conditions (what must be true) and negative conditions (what must be false).
Question 17
Which sequence of conditions must be met to apply a 10% discount?
// Inputs: isMember, total, isSeasonSale
IF isMember
IF total >= 100
IF isSeasonSale
discount = 0.20
ELSE
discount = 0.10
ELSE
discount = 0.05
ELSE
IF isSeasonSale AND total >= 150
discount = 0.15
ELSE
discount = 0.00
- Member, total >= 100, season sale
- Not a member, total >= 150, season sale
- Member, total >= 100, not season sale (correct answer)
- Member, total < 100, not season sale
Explanation: This question tests understanding of nested conditionals in AP Computer Science Principles, requiring students to identify the exact path to a specific discount value. Nested conditionals create a tree of decisions where each branch represents a different combination of conditions leading to unique outcomes. In this shopping cart scenario, the 10% discount is located in a specific branch that requires navigating through multiple decision points in the correct sequence. Choice C is correct because to reach discount = 0.10, the code must first verify isMember is true, then confirm total >= 100, and finally determine that isSeasonSale is false, executing the ELSE clause of the innermost conditional. Choice A is incorrect because when all three conditions are true (member, total >= 100, season sale), the discount would be 0.20, not 0.10. To help students: Map out all possible paths and their outcomes in a tree diagram, highlight that ELSE clauses are as important as IF conditions, and practice identifying 'negative' requirements (what must be false). Remind students that reaching inner conditionals requires satisfying all outer conditions first.
Question 18
If isMember=false and isSeasonSale=false are true, what is the discount when total=200?
// Inputs: isMember, total, isSeasonSale
IF isMember
IF total >= 100
IF isSeasonSale
discount = 0.20
ELSE
discount = 0.10
ELSE
discount = 0.05
ELSE
IF isSeasonSale AND total >= 150
discount = 0.15
ELSE
discount = 0.00
- 0.15
- 0.00 (correct answer)
- 0.10
- 0.05
Explanation: This question tests understanding of nested conditionals in AP Computer Science Principles, focusing on how compound conditions with AND operators work. Nested conditionals allow for complex decision-making by combining multiple conditions, and the AND operator requires all connected conditions to be true for the overall condition to pass. In this scenario, with isMember=false, the code enters the outer ELSE block, then evaluates 'isSeasonSale AND total >= 150' where isSeasonSale is false, causing the entire compound condition to fail. Choice B is correct because when isMember is false and isSeasonSale is false, the condition 'isSeasonSale AND total >= 150' evaluates to false (since false AND true = false), leading to the ELSE clause that sets discount = 0.00. Choice A is incorrect because 0.15 requires both isSeasonSale to be true AND total >= 150, but isSeasonSale is false. To help students: Create truth tables for compound conditions, emphasize that AND requires ALL parts to be true, and practice evaluating complex conditions step by step. Remind students that with AND, if any part is false, the entire condition is false, regardless of other values.
Question 19
Given this shopping-cart pseudo-code, what will the discount be if isMember=true, total=100, isSeasonSale=false?
// Inputs: isMember, total, isSeasonSale
IF isMember
IF total >= 100
IF isSeasonSale
discount = 0.20
ELSE
discount = 0.10
ELSE
discount = 0.05
ELSE
IF isSeasonSale AND total >= 150
discount = 0.15
ELSE
discount = 0.00
- 0.20
- 0.05
- 0.10 (correct answer)
- 0.00
Explanation: This question tests understanding of nested conditionals in AP Computer Science Principles, specifically how the deepest nested ELSE clause executes. Nested conditionals create decision trees where each branch leads to different outcomes based on cascading conditions. In this scenario, the code navigates through three levels: first confirming membership (true), then verifying the total meets the threshold (100 >= 100, which is true), and finally checking the season sale status (false), which directs execution to the ELSE clause. Choice C is correct because when isMember=true, total>=100, but isSeasonSale=false, the code follows the path through the first two IF statements but takes the ELSE branch at the third level, setting discount = 0.10. Choice A is incorrect because 0.20 requires isSeasonSale to be true, which contradicts the given input. To help students: Create decision trees showing all possible paths, use consistent indentation to visualize nesting depth, and practice predicting outcomes before tracing code. Remind students that ELSE clauses execute when their corresponding IF condition is false, even in deeply nested structures.
Question 20
In this shopping-cart pseudo-code, which conditions must be met to apply a 20% discount?
// Inputs: isMember, total, isSeasonSale
IF isMember
IF total >= 100
IF isSeasonSale
discount = 0.20
ELSE
discount = 0.10
ELSE
discount = 0.05
ELSE
IF isSeasonSale AND total >= 150
discount = 0.15
ELSE
discount = 0.00
- Member, total < 100, season sale
- Not a member, total >= 150, season sale
- Member, total >= 100, season sale (correct answer)
- Member, total >= 100, not season sale
Explanation: This question tests understanding of nested conditionals in AP Computer Science Principles, focusing on tracing through multiple layers of decision-making. Nested conditionals create a hierarchy of conditions where inner conditions are only evaluated if outer conditions are met. In this shopping cart scenario, the code checks membership status first, then purchase total, and finally season sale status to determine the appropriate discount. Choice C is correct because to reach the 20% discount (0.20), the code must first confirm isMember is true, then verify total >= 100, and finally check that isSeasonSale is true - all three conditions must be satisfied in this exact nested order. Choice A is incorrect because it specifies total < 100, which would lead to the 5% discount path instead. To help students: Use indentation to visualize nesting levels, trace through each path systematically with specific values, and create truth tables for complex conditions. Remind students that in nested structures, the order of conditions matters and inner conditions are only reached if outer conditions pass.