Logical Operators
AND is a logical operator that combines conditions. The combined condition is true only when every condition joined by AND is true. If any one of them is false, the result is false. A single true condition is not enough.
In Python, AND is written as and. It sits between the conditions, for example a condition that checks whether the quiz score is at least 8 and the homework is done. This is true only for someone who scored at least 8 and also completed the homework. Scoring 8 with no homework gives false, because the AND rule needs every part to pass. It does not let one condition make up for another.
| A | B | A AND B |
|---|---|---|
| True | True | True |
| True | False | False |
| False | True | False |
| False | False | False |
The truth table shows the only row that produces true: both inputs are true. Every other combination produces false.
For a worked rule, a school trip goes ahead only if the deposit is paid and the consent form is returned. If the deposit is paid but the form is missing, the trip does not go ahead. The missing form makes the whole AND condition false.
When you write an algorithm, check that the rule really needs every condition. AND does not choose between alternatives; it requires all the conditions it combines to pass. If one condition alone should be enough, AND is the wrong choice.
points = int(input("Points: "))
time_left = int(input("Time left: "))
if points >= 10 and time_left > 0:
print("Bonus awarded")
else:
print("No bonus")Output when the user types 12, 3:
Points: 12
Time left: 3
Bonus awarded Edexcel GCSE Computer Science · Logical Operators
Edexcel GCSE Computer Science · Logical Operators