Boolean Expressions

Help Questions

AP Computer Science Principles › Boolean Expressions

Questions 1 - 10
1

An online store gives free shipping if if (isMember OR purchaseOver100). In the given programming task, what is the result of the boolean expression when isMember is false and purchaseOver100 is true?

True, only if both conditions are true

False, because OR behaves like AND

False, because membership is required

True, because one condition is true

Explanation

This question tests understanding of boolean expressions in programming, specifically evaluating OR operations when conditions have mixed values. Boolean expressions evaluate to true or false based on the logic of conditions set within an algorithm, often controlling decision branches. In this scenario, the boolean expression (isMember OR purchaseOver100) determines free shipping eligibility through either membership or high purchase amount. Choice B is correct because with purchaseOver100 being true, the OR expression evaluates to true even though isMember is false, since OR requires only one true condition. Choice D is incorrect due to fundamental confusion between OR and AND operators, mistakenly treating OR as if it behaves like AND. To help students: Create comparison tables showing OR vs AND behavior with identical inputs. Practice with everyday examples like 'free entry with membership OR student ID' to reinforce the inclusive nature of OR.

2

An access control algorithm unlocks a door only if if (userIsAdmin AND withinBusinessHours). Based on the algorithm described, what is the result of the boolean expression when withinBusinessHours is false?

False, only when userIsAdmin is false

False, even if userIsAdmin is true

True, if userIsAdmin OR withinBusinessHours

True, because admin overrides time

Explanation

This question tests understanding of boolean expressions in programming, specifically evaluating AND operations when one condition is false. Boolean expressions evaluate to true or false based on the logic of conditions set within an algorithm, often controlling decision branches. In this scenario, the boolean expression (userIsAdmin AND withinBusinessHours) determines whether a door unlocks when both conditions must be met. Choice B is correct because when withinBusinessHours is false, the entire AND expression evaluates to false regardless of userIsAdmin's value, since AND requires both conditions to be true. Choice A is incorrect due to misunderstanding operator precedence, falsely assuming admin status can override the AND logic. To help students: Create truth tables showing all possible combinations of the two variables. Emphasize that AND expressions are only true when ALL conditions are true, using real-world analogies like needing both a key AND the correct code to open a safe.

3

A weather alert system issues an alert if (tempBelowFreezing AND precipitationLikely). Based on the algorithm described, which condition must be true for an alert?

tempBelowFreezing is true and precipitationLikely is true

tempBelowFreezing is true or precipitationLikely is true

Either condition is false to be safe

tempBelowFreezing is false and precipitationLikely is true

Explanation

This question tests understanding of boolean expressions in programming, specifically evaluating AND operations for safety-critical systems. Boolean expressions evaluate to true or false based on the logic of conditions set within an algorithm, often controlling decision branches like weather alerts. In this scenario, the boolean expression (tempBelowFreezing AND precipitationLikely) determines when to issue a weather alert based on temperature and precipitation conditions. Choice A is correct because AND operations require both conditions to be true - the system only alerts when it's both below freezing AND precipitation is likely, indicating potential ice or snow hazards. Choice B is incorrect due to confusing AND with OR logic, which would create too many false alerts. To help students: Use real-world safety examples where multiple conditions must align, like 'alert only when cold AND wet.' Draw Venn diagrams showing the intersection where both conditions overlap.

4

An online store applies a premium discount if if (isMember AND purchaseOver50). In the given programming task, which condition must be true for a premium discount to occur in this algorithm?

isMember is true and purchaseOver50 is false

isMember is true and purchaseOver50 is true

isMember is false and purchaseOver50 is true

isMember is true or purchaseOver50 is true

Explanation

This question tests understanding of boolean expressions in programming, specifically identifying when AND operations evaluate to true. Boolean expressions evaluate to true or false based on the logic of conditions set within an algorithm, often controlling decision branches. In this scenario, the boolean expression (isMember AND purchaseOver50) determines when a premium discount is applied, requiring both membership and minimum purchase amount. Choice A is correct because AND operations require both conditions to be true simultaneously for the entire expression to evaluate to true. Choice B is incorrect due to confusing AND with OR logic, mistakenly thinking only one condition needs to be true. To help students: Use Venn diagrams to visualize AND as the intersection of two sets. Practice with real-world scenarios where multiple requirements must all be met, like needing both a ticket AND valid ID to board a plane.

5

An access control algorithm unlocks a door only if (userIsAdmin AND withinBusinessHours). Based on the algorithm described, what is the result of the boolean expression when userIsAdmin is true and withinBusinessHours is false?

False, because it is not a weekend

True, because one condition is true

True, because admin overrides hours

False, because both must be true

Explanation

This question tests understanding of boolean expressions in programming, specifically evaluating AND operations with mixed true/false conditions. Boolean expressions evaluate to true or false based on the logic of conditions set within an algorithm, often controlling decision branches like access control. In this scenario, the boolean expression (userIsAdmin AND withinBusinessHours) determines whether a door unlocks when both conditions about user privileges and timing are evaluated. Choice B is correct because it accurately reflects that AND operations require both conditions to be true for the overall expression to be true - since withinBusinessHours is false, the entire expression evaluates to false. Choice C is incorrect due to confusing AND with OR logic, a common error where students think one true condition is sufficient for an AND expression. To help students: Use truth tables to visualize AND operations, showing that T AND F = F. Practice with real-world scenarios like 'you need both a ticket AND valid ID to enter' to reinforce that both conditions must be met.

6

An email filter auto-archives if (NOT fromTrustedSender AND hasSpamKeywords). Based on the algorithm described, which condition must be true for archiving?

Sender is trusted and keywords appear

Sender is not trusted or keywords appear

Sender is not trusted and keywords appear

Sender is trusted or keywords do not appear

Explanation

This question tests understanding of boolean expressions in programming, specifically evaluating AND operations with NOT operators in spam filtering. Boolean expressions evaluate to true or false based on the logic of conditions set within an algorithm, often controlling decision branches like email archiving. In this scenario, the boolean expression (NOT fromTrustedSender AND hasSpamKeywords) determines when to auto-archive emails based on sender trust and content. Choice B is correct because it accurately describes both required conditions: the sender must not be trusted (NOT fromTrustedSender = true) AND spam keywords must be present - only emails that are both untrusted and spammy get archived. Choice C is incorrect due to confusing AND with OR logic, which would archive too many legitimate emails. To help students: Break down compound conditions into parts, evaluating NOT first. Use examples like 'archive if untrusted AND suspicious' to reinforce that both red flags must be present.

7

In an access control system, a badge opens a lab door only when if (userIsAdmin AND withinBusinessHours) is true; otherwise it logs a denied attempt. Based on the algorithm described, which condition must be true for access to occur in this algorithm?

userIsAdmin is true AND withinBusinessHours is true

userIsAdmin is true OR withinBusinessHours is true

withinBusinessHours is true, regardless of userIsAdmin

userIsAdmin is true, regardless of withinBusinessHours

Explanation

This question tests understanding of boolean expressions in programming, specifically evaluating AND operations for access control logic. Boolean expressions evaluate to true or false based on the logic of conditions set within an algorithm, often controlling decision branches like granting or denying access. In this scenario, the boolean expression (userIsAdmin AND withinBusinessHours) determines whether the lab door opens, requiring both conditions to be simultaneously true. Choice B is correct because it accurately reflects the logic of the AND operator, which requires both userIsAdmin and withinBusinessHours to be true for the entire expression to evaluate to true. Choice A is incorrect due to confusing AND with OR logic, a common error where students assume only one condition needs to be met. To help students: Use truth tables to visualize how AND operations require all conditions to be true, unlike OR operations. Practice with real-world scenarios like security systems where multiple conditions must be satisfied for access.

8

A weather alert system sends a push notification when if (tempBelowFreezing AND precipitationLikely) is true; otherwise it posts a normal forecast. Based on the algorithm described, which condition must be true for an alert to occur in this algorithm?

tempBelowFreezing is false AND precipitationLikely is true

tempBelowFreezing is true OR precipitationLikely is true

tempBelowFreezing is true AND precipitationLikely is true

precipitationLikely is true, regardless of temperature

Explanation

This question tests understanding of boolean expressions in programming, specifically evaluating AND operations for weather alert systems. Boolean expressions evaluate to true or false based on the logic of conditions set within an algorithm, often controlling decision branches like sending notifications. In this scenario, the boolean expression (tempBelowFreezing AND precipitationLikely) determines whether a push notification is sent for potentially icy conditions. Choice C is correct because it accurately reflects the logic of the AND operator, requiring both temperature below freezing and likely precipitation to trigger an alert. Choice A is incorrect due to confusing AND with OR logic, assuming either condition alone could trigger the alert. To help students: Use real-world examples where multiple conditions create a specific hazard (ice requires both cold and moisture). Practice identifying when AND logic is appropriate versus OR logic based on the problem context.

9

An access control system logs an alert if if (NOT userIsAdmin AND accessAfterHours). Based on the algorithm described, what is the result of the boolean expression when userIsAdmin is true?

False, because NOT userIsAdmin is false

True, because admin implies after-hours access

False, only if accessAfterHours is false

True, if accessAfterHours is true

Explanation

This question tests understanding of boolean expressions in programming, specifically evaluating expressions with NOT operators applied to the first condition. Boolean expressions evaluate to true or false based on the logic of conditions set within an algorithm, often controlling decision branches. In this scenario, the boolean expression (NOT userIsAdmin AND accessAfterHours) determines when to log an alert for non-admin after-hours access. Choice B is correct because when userIsAdmin is true, NOT userIsAdmin evaluates to false, making the entire AND expression false regardless of accessAfterHours value. Choice A is incorrect due to ignoring the NOT operator's effect, failing to recognize that admin users never trigger alerts in this system. To help students: Practice evaluating NOT operators as the first step before considering AND/OR operations. Use truth tables to systematically work through all possible combinations of boolean values.

10

An access control algorithm unlocks a door if if (userIsAdmin AND withinBusinessHours). Based on the algorithm described, how would changing AND to OR impact the outcome?

Unlocks when either condition is true

Unlocks only when both conditions are false

Unlocks only when both conditions are true

Unlocks only when withinBusinessHours is false

Explanation

This question tests understanding of boolean expressions in programming, specifically comparing the behavioral differences between AND and OR operators. Boolean expressions evaluate to true or false based on the logic of conditions set within an algorithm, often controlling decision branches. In this scenario, changing the boolean expression from (userIsAdmin AND withinBusinessHours) to (userIsAdmin OR withinBusinessHours) fundamentally alters when the door unlocks. Choice B is correct because OR makes the door unlock when either condition is true, creating a more permissive access policy compared to AND which requires both. Choice A is incorrect due to describing the original AND behavior rather than recognizing how OR changes the logic. To help students: Create side-by-side truth tables comparing AND vs OR with the same inputs. Use security scenarios to illustrate how OR creates more access points while AND creates stricter requirements.

Page 1 of 3