Many questions involve multiple conditions. For example, to determine if a number is an even number greater than 100, then you need to check two things at once:
Because both must be true, we join these statements with βandβ. If either of these conditions could be true, then we would join them with βorβ.
Are both \(\texttt{ans1}\) and \(\texttt{ans2}\) true?
|
ans1 | ans2
\(\text{Is at least one of}\ \texttt{ans1}\ \text{or}\ \texttt{ans2}\ \text{true?}\)
The result of joining logical statements are exactly what you would expect from everyday language: AND is true only when both sides are true, while OR is true when at least one side is true.
P = 1;
Q = 10;
R = -4;
P <= R & P > Q % β false & false: 0 (logical)
R < 0 & R < Q % β true & true: 1 (logical)
Q == R | Q == P % β false | false: 0 (logical)
P < Q | P < R % β true | false: 1 (logical)
~(P < Q & P < R) % β NOT (true & false): 1 (logical)
P > Q | P > R % β false | true: 1 (logical)
Checkpoint24.Combining Logical Statements.
Given age = 25 and hasLicense = true, which expression is the most readable way to ask "Is the person at least 18 years old AND has a driverβs license?"