While making decisions, we often need to compound multiple conditions. For instance, 1<x<10 requires x>1 AND x<10. How to say AND in Python? What about x>1 OR y<1?
1. A boolean expression (or logical expression) evaluates to one of two states true or false. Python provides the boolean type that can be either set to False or True. Many functions and operations return boolean values.
The not keyword can also be used to inverse a boolean value.
>>> not True False
The evaluation using the and and or operators follow these rules:
and and or both evaluate expressions from left to right while and have higher precedence.
with and, if all values are True, returns the last evaluated value. If any value is False, returns the first False value, and ignores the rest. This is called short-circuit.
or returns the first True value, and ignores the rest(short-circuit). If all are False, returns the last False.
x Returns True if x is True, False otherwise x and y Returns x if x is False, y otherwise x or y Returns y if x is False, x otherwise
3. Operator Precedence: See the table below. Highest precedence at the top, lowest at the bottom. Operators in the same box evaluate left to right.
C. Try this:
1. Let the user enter three side lengths of a triangle as input, print out if it is an equilateral, Isosceles, or scalene triangle.
2. Let the user enter measurements of a triangle's three interior angles as input, print out if it is an acute, right, or obtuse triangle.