Boolean conditions

Boolean variables are like numeric variables. It’s possible to assign expressions, perform operations, and print their values.
To check if two values are equal we can use == operator:
a = 10
b = 20 / 2
print(a == b)  # True

c = a == b
print(c)       # True

d = 3
print(a == d)  # False
Here the expression a == b results in True as 10 is equal to 20 / 2. We can even assign the result of a == b check to another variable c and print its value.
 
In Python, the value of True can be interpreted as 1 and the value of False can be interpreted as 0. So, we can even perform additions and multiplications with boolean values:
print(True + True)        # 2
print(True * 10)          # 10
print(True + False - 3)   # -2
print(10 * False)         # 0
This allows to treat boolean values exactly like numeric values and perform computations.

Challenge

As you already know how to play with boolean variables, try to solve this challenge with pen and paper (or even in your head if you’re a pro 😎).
What will be the output of the following program?
a = 7
b = 2
c = a == b
d = a == 14 / 2
e = a * d * 10
f = a * c
print(c, d, f)
 
To check your solution you need to sign in
Sign in to continue