Logic in Computer Science and Boolean Thinking
A free Logic lesson from the “Logic Applications and Final Review” unit, with a worked example and practice problems including step-by-step solutions.
Computer programs often branch on true/false conditions. Boolean thinking makes truth tables practical. Learning objective: Connect truth values, conditionals, and and/or logic to code. Prerequisite: No formal prerequisite. Work in this lesson starts with ordinary language, then connects the idea to symbols only after the meaning is clear. Example 1: An algebra rule may apply only if a denominator is not zero. Example 2: A program condition such as 'if score >= 70 and quiz submitted' uses logic to decide what happens next. A common misconception is to treat familiar wording as proof; instead, check exactly what the statement says and what follows from it.
What you'll learn
- Connect truth values, conditionals, and and/or logic to code
- Explain the idea in plain English before using symbols
- Use examples, non-examples, or counterexamples to check the reasoning
Worked example
Problem. Example case A (Logic in Computer Science and Boolean Thinking): Worked example: Code runs when isLoggedIn (True) AND isAdmin (True). Does it run?
- Worked Example: First identify exactly what the question is asking: Example case A (Logic in Computer Science and Boolean Thinking): Worked example: Code runs when isLoggedIn (True) AND isAdmin (True). Does it run?
- Compare each choice with the stated logical rule, and eliminate choices that change the claim's meaning.
- && means both must be true.
- isLoggedIn is True; isAdmin is True.
Answer: True
Practice problems
1. Practice case A (Logic in Computer Science and Boolean Thinking): Practice: Code runs when isLoggedIn (True) AND isAdmin (True). Does it run?
Choices: True · False
Show solution
- Warm-up: First identify exactly what the question is asking: Practice case A (Logic in Computer Science and Boolean Thinking): Practice: Code runs when isLoggedIn (True) AND isAdmin (True). Does it run?
- Compare each choice with the stated logical rule, and eliminate choices that change the claim's meaning.
- && means both must be true.
- isLoggedIn is True; isAdmin is True.
- So the AND condition is True.
- Verify the selected choice by checking that it preserves the stated logical meaning and that the other choices change the rule or claim.
Answer: True
2. Practice case B (Logic in Computer Science and Boolean Thinking): Practice: A page is shown when isOwner (True) OR isEditor (True). Is it shown?
Choices: True · False
Show solution
- Warm-up: First identify exactly what the question is asking: Practice case B (Logic in Computer Science and Boolean Thinking): Practice: A page is shown when isOwner (True) OR isEditor (True). Is it shown?
- Compare each choice with the stated logical rule, and eliminate choices that change the claim's meaning.
- || means at least one must be true.
- isOwner is True; isEditor is True.
- So the OR condition is True.
- Verify the selected choice by checking that it preserves the stated logical meaning and that the other choices change the rule or claim.
Answer: True
3. Practice case C (Logic in Computer Science and Boolean Thinking): Practice: A warning shows when NOT isSaved. isSaved is True. Does the warning show?
Choices: True · False
Show solution
- Warm-up: First identify exactly what the question is asking: Practice case C (Logic in Computer Science and Boolean Thinking): Practice: A warning shows when NOT isSaved. isSaved is True. Does the warning show?
- Compare each choice with the stated logical rule, and eliminate choices that change the claim's meaning.
- ! flips the truth value.
- isSaved is True.
- So !isSaved is False.
- Verify the selected choice by checking that it preserves the stated logical meaning and that the other choices change the rule or claim.
Answer: False
4. Practice case D (Logic in Computer Science and Boolean Thinking): Practice: Access = (hasKey AND hasPin) OR isManager. hasKey=True, hasPin=False, isManager=False. Access granted?
Choices: True · False
Show solution
- Warm-up: First identify exactly what the question is asking: Practice case D (Logic in Computer Science and Boolean Thinking): Practice: Access = (hasKey AND hasPin) OR isManager. hasKey=True, hasPin=False, isManager=False. Access granted?
- Compare each choice with the stated logical rule, and eliminate choices that change the claim's meaning.
- Evaluate the AND in parentheses first.
- hasKey AND hasPin is False; isManager is False.
- The OR result is False.
- Verify the selected choice by checking that it preserves the stated logical meaning and that the other choices change the rule or claim.
Answer: False
5. Practice case E (Logic in Computer Science and Boolean Thinking): Practice: In code, !(a && b) is equivalent to:
Choices: !a || !b · !a && !b · a || b · a && !b
Show solution
- This is De Morgan's Law in code.
- NOT of (a AND b) becomes (NOT a) OR (NOT b).
- The connective flips and both parts are negated.
Answer: !a || !b
Practice this interactively with instant feedback and an AI tutor.
Practice Logic in Computer Science and Boolean Thinking Take the free placement check