Raspberry Logical Operators
In previous lessons, we have learned and used common operators, such as the comparison operators, arithmetic operators, and “and" logic operator, that is, Boolean “and". First, let's review these common logical operators.
In this lesson, we will use a new logical operator Boolean “or". An example is as follows:
1 if x or y :
2 print "variables x and y are both true, or one of them is true"
3 else:
4 print "variables x and y are not true"
The output result of the above example is “variables x and y are both true, or one of them is true". Similarly, we can use Boolean “or" to judge whether the temperature or humidity in the environment is within an appropriate range. If one of them fails to meet the requirements, we will sound an alarm.