We can operate on Boolean values:
(True and True) == True #a and b: a is True and b is True
((True and False) == False ) == False #The value of the whole expression
#is False, since (True and False) == False
(True or False) == True #a or b: at least one of a or b is true
#The whole expression is True in this case
(True or True) == True #The value of the expression is True
not True
not False
not (True or False)
Note: the Boolean "or" isn't quite the same as the English "or". "For dessert, I'll have pie or I'll have ice cream" in English means that I'll only have one dessert. In Python, it means that I'll have at least one dessert (since it means that one of "I'll have pie" or "I'll have ice cream" is true)
How do you express the English "I'll have pie or I'll have ice cream?" Define two Boolean variables:
will_have_pie = False
will_have_ice_cream = True
print "Reasonable amount of dessert" the variables satisfy the English "For dessert, I'll have pie or I'll have ice cream"
if (will_have_pie and not will_have_ice_cream) or (not will_have_pie and will_have_ice_cream):
print("Reasonable amount of dessert")
else:
print("Unreasonable amount of dessert")