OR Operator
The full text of this chapter, to read or revisit. To practise, do the exercises.
βΆ Do the exercisesExercise 1 β OR Operator
The or operator is a logical operator that returns True if at least one side is True. Otherwise, it returns False.
Here is a truth table for the or operator with 2 variables (A or B = ?). It shows all possible combinations of True and False.
Exercise 2 β OR Operator
We can also try to display the truth table with code !
print("False or False =", False or False)
print("True or False =", True or False)
print("False or True =", False or True)
print("True or True =", True or True)Remember, or returns True if at least one side is True.
Exercise 3 β Did you get OR?
Match each formula of the left with its result on the right.
True or TrueTrue or FalseFalse or TrueFalse or FalseTrueTrueTrueFalseExercise 4 β OR Operator Quiz
What will be the result of False or True?
TrueFalseErrorNoneHint : With OR operator, if at least one side is True, the result is True. Since one side is True, the result is True.
Exercise 5 β Match OR Results
Match each OR operation with its correct result. In these type of operations, you're gonna want to read from left to right, evaluating what's within parentheses first if there are any, AND is evaluated before OR (similar to multiplication before addition).
True or True or TrueFalse or True or FalseFalse or False or FalseTrue or False or TrueTrueTrueFalseTrueExercise 6 β Match Complex Boolean Results
Match each boolean operation with its correct result. Remember: evaluate what's in parentheses first, then AND operations, and finally OR operations (reading left to right).
(True or False) and TrueFalse or (True and False)(False and True) or TrueTrue and (False or True)(True and False) or FalseTrueFalseTrueTrueFalse