2.3. And/Or#
It is possible to build more complex conditions using and or or.
and: both conditions have to beTrueto evaluate asTrueor: only one condition has to beTrueto evaluate asTrue
One way to remember this is:
if you want fish and chips, you are expecting both.
if you want fish or chips, you are only expecting one or the other, but you’re also happy if you get both.
You can visualise these rules using a truth table:
2.3.1. Exercises#
Question 1
Does the following program return True or False?
x = 4
print(x > 2 or x < 10)
lock
This solution is locked.
Question 2
Does the following program return True or False?
x = 1
print(x < 2 and x > 3)
lock
This solution is locked.
Question 3
Does the following program return True or False?
x = 6
y = 2
z = x * y
print(z > x or y > 2)
lock
This solution is locked.
Question 4
Does the following program return True or False?
day = 5
month = 'November'
print(day == 5 and month != 'November')
lock
This solution is locked.