Checkpoint 25.6.1.
What does the code sample above do?
- Produces an error message
- Try running it!
- Prints "That is a valid color." then "Done"
- Correct
- Prints "Done"
- Try running it!
or splits color == "blue" from "green". Each of those is evaluated on its own. Does color == "blue"? No that is False. How about "green". Is that True or False???
"" is considered True in Python. So green counts as True. Since the value on the left of or is False, and the value on the right is True (according to Python), the final value of the expression is True.
| color == "blue" | or | green |
| False | or | True |
| True | ||
or are expressions that make sense on their own as logical expressions. We have to repeat the color == part so that "green" is not evaluated on its own:
and or or MUST be logical expressions (True/False). You can’t have something that looks like … or "blue" or … and 10 or that part will just count as True.