Nested Conditionals - AP Computer Science Principles

  1. If isMember is true and total is 100 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
    Answer: 20% This question tests understanding of nested conditionals in AP Computer Science Principles, focusing on boundary conditions where values exactly meet threshold requirements. Nested conditionals require careful attention to comparison operators (>= vs >) as these determine whether boundary values satisfy conditions. With isMember = true, total = 100, and seasonal sale active, the code follows: IF isMember (true) → IF total >= 100 (true, since 100 >= 100) → IF isSeasonalSale (true) → discount = 20. Choice D is correct because all three conditions are satisfied, with the key insight being that 100 exactly meets the >= 100 threshold. Choice B would be the result if the total were 99 instead of 100, highlighting the importance of boundary testing. To help students avoid errors with boundary conditions, practice with values at, just above, and just below thresholds. Teach students to pay special attention to inclusive (>=, <=) versus exclusive (>, <) comparisons, as these often determine program behavior at critical points.
  2. 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
    Answer: 0.10 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.
  3. Given this shopping cart code, what will the discount be if isMember is true, total is 120, and isSeasonalSale is false? // 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
    Answer: 15% This question tests understanding of nested conditionals in AP Computer Science Principles, focusing on tracing through multiple decision levels with specific variable values. Nested conditionals enable complex decision-making by evaluating conditions in a hierarchical structure, where inner conditions depend on outer conditions being met. Given the values isMember = true, total = 120, and isSeasonalSale = false, the code follows this path: first IF (isMember) is true, second IF (total >= 100) is true since 120 >= 100, third IF (isSeasonalSale) is false, leading to the ELSE branch. Choice B is correct because this exact path results in discount = 15, as members who spend at least $100 outside of seasonal sales receive a 15% discount. Choice A would require isSeasonalSale to be true, which contradicts the given conditions. To help students succeed with these problems, teach them to write out each condition's evaluation (true/false) next to the code as they trace through it. Encourage students to verify their path by checking that all conditions leading to their answer match the given scenario.
  4. 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"
    Answer: GREEN 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.
  5. 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"
    Answer: isMember true, total >= 100, isSeasonSale true 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.
  6. If isMember is false, total is 150, and isSeasonalSale is true, 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
    Answer: 10% This question tests understanding of nested conditionals in AP Computer Science Principles, specifically the ability to trace execution paths when the first condition is false. Nested conditionals allow programs to make complex decisions by evaluating conditions in a hierarchical manner, with different paths for different scenarios. In this case, the code first checks if the customer is a member (false), directing execution to the ELSE branch for non-members, then checks if the total is at least $150 (true), and finally checks if it's a seasonal sale (true). Choice C is correct because following this path: isMember is false → go to ELSE branch → total (150) >= 150 is true → isSeasonalSale is true → discount = 10. Choice D would be incorrect because it represents the maximum discount, which is only available to members during seasonal sales. To help students understand this concept, use flowcharts to visualize the different paths through nested conditions, and practice tracing with specific variable values. Emphasize that when the first condition is false, the entire first branch is skipped, and execution jumps directly to the ELSE clause.
  7. 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"
    Answer: Heat Advisory 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.
  8. 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
    Answer: 5% 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 $100 threshold (false since 99 < 100), which directs execution to the inner ELSE branch. Choice A is correct because when isMember is true but total < 100, the code follows the path: IF isMember (true) → IF total >= 100 (false) → ELSE → discount = 5, regardless of seasonal sale status. Choice C is incorrect because even though it's a seasonal sale, the 20% discount requires a minimum purchase of $100, 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.
  9. 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
    Answer: Member, total >= 100, season sale 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.
  10. If isMember is false and total is 200 with no 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
    Answer: 0% This question tests understanding of nested conditionals in AP Computer Science Principles, specifically how non-members are treated in the discount system. Nested conditionals allow programs to implement different logic branches based on initial conditions, creating separate pathways for different user types. When isMember is false, the code immediately branches to the ELSE clause for non-members, then checks if total >= 150 (true since 200 >= 150), and finally checks isSeasonalSale (false). Choice A is correct because following this path: IF isMember (false) → ELSE → IF total >= 150 (true) → IF isSeasonalSale (false) → ELSE → discount = 0. Choice B would be correct if it were a seasonal sale, but the problem states there's no seasonal sale. To help students understand this concept, emphasize that non-members have more restrictive discount conditions - they need both a high purchase amount AND a seasonal sale to get any discount at all. Practice problems should include various combinations to help students see how changing one variable can completely alter the outcome.
  11. Given this shopping-cart pseudo-code, what will the discount be if isMember=true, total=90, 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
    Answer: 0.05 This question tests understanding of nested conditionals in AP Computer Science Principles, focusing on how early condition failures affect execution paths. Nested conditionals evaluate conditions sequentially, and when an outer condition fails, all inner conditions are skipped regardless of their values. In this scenario, the code first checks if the customer is a member (true), then checks if total >= 100, which fails since total is 90, causing the program to skip the innermost isSeasonSale check entirely. Choice A is correct because when isMember is true but total < 100, the code executes the ELSE block of the second IF statement, setting discount = 0.05, regardless of the isSeasonSale value. Choice C is incorrect because 0.20 requires all three conditions to be true, including total >= 100, which is not met here. To help students: Trace execution step-by-step, marking which conditions are evaluated and which are skipped, use different colored pens for different execution paths, and practice identifying the 'controlling condition' that determines the path. Emphasize that in nested structures, failing an outer condition means inner conditions are never even checked.
  12. 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
    Answer: C 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.
  13. 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
    Answer: Not a member and (not season sale or total < 150) 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).
  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"
    Answer: enemyNear true, health >= 30, hasSpecial true 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.
  15. 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
    Answer: 0.15 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.
  16. 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
    Answer: B 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.
  17. What condition would cause the code to follow the alternative path setting discount to 0? // 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
    Answer: Not a member and total < 150 This question tests understanding of nested conditionals in AP Computer Science Principles, specifically identifying paths that lead to a discount of 0. Nested conditionals create multiple execution paths, and understanding which conditions lead to specific outcomes is crucial for debugging and program analysis. The code has two paths that set discount to 0: when a non-member has a total >= 150 but it's not a seasonal sale, or when a non-member has a total < 150 (regardless of seasonal sale status). Choice B is correct because it represents the path: isMember is false → total < 150 → discount = 0, which is the final ELSE clause that catches all non-members who don't spend enough. Choice C is incorrect because members with total >= 100 during seasonal sales receive a 20% discount, not 0%. To help students understand this concept, create a truth table showing all possible combinations of conditions and their outcomes, highlighting which combinations result in no discount. Emphasize that in nested structures, the deepest ELSE clauses often serve as catch-all conditions for cases that don't meet any special criteria.
  18. 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"
    Answer: isMember false and total < 150 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.
  19. 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"
    Answer: not night, traffic not high, hasPedestrian true 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.
  20. Which sequence of conditions must be met for a 15% 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
    Answer: Member, total >= 100, not seasonal This question tests understanding of nested conditionals in AP Computer Science Principles, requiring students to identify the exact sequence of conditions for a specific outcome. Nested conditionals allow for precise control over program flow by checking multiple conditions in sequence, with each level adding more specificity. In this shopping cart system, a 15% discount is achieved through a very specific path: the customer must be a member, spend at least $100, but the sale must not be seasonal. Choice A is correct because it follows the path: IF isMember (true) → IF total >= 100 (true) → IF isSeasonalSale (false) → ELSE → discount = 15. Choice B is incorrect because members with total < 100 receive only a 5% discount regardless of seasonal status. To help students master this skill, use code tracing exercises where they manually follow each branch, and create scenarios that test their understanding of when ELSE branches execute. Remind students that ELSE branches execute when their corresponding IF condition is false, making 'not seasonal' the key to reaching the 15% discount.

Start this quiz