Level I
Play with logic expressions
Once you have learned how to calculate simple math with Python, Python can tell you whether what you wrote is True or is False. Please note we wrote the first letter in capital letter, this is how it is written in this language.
It is important you remember that in order to ask whether something is “equivalent to” something, you need to put “==”, instead of “=”. Look at this!
Here you have met some of the main “boolean expressions”. Let’s learn some more:
- How to say greater or less than? Use “>” or “<”, respectively.
- How to say greater than or equal to? Use “>=”.
- How to say less than or equal to? Use “<=”.
- How to say equivalent to? Use “==”.
- How to say it’s NOT equivalent? Use “!=”.
Now that you have been familiarized with the concept of booleans, let’s combine some boolean expressions. Quick example:
AND
It is true that Mariana was born in Colombia, and it is true that Paula was born in the UK.
So if I ask you, tell me if it’s true that “Mariana was born in Colombia and Paula was born in France”, your answer should be “False”. Because although one of the assumptions is correct, BOTH have to be correct (I said “and”).
OR
If I say “or”, in this case the answer would be True, because one of them is True, and that is enough.
NOT
This is just a way to obtain the opposite truth value (False becomes True, and True becomes False).
Let’s translate into Python:
Previous lesson
Play with simple math
Next lesson
Play with conditionals