Chapter 4b - Conditionals
if runs a block only when the test is true. else runs when it is not.
if n == 1:
print("Outside is hot")
else:
print("not hot")
π§ͺ Try it
Mini quiz β if and elseβ
if and else
1 / 2If n is 1, which branch runs?
if n == 1:print("Outside is hot")else:print("not hot")
Pick an answer to see if you are right.
Zodiac project
Challenge: weather lineβ
Write weather(n) so it returns "hot" if n is 1, otherwise "cool".
Even and oddβ
n % 2 == 0 means even.
Mini quiz β ifβ
if
1 / 2What does else do?
Pick an answer to see if you are right.
Exercisesβ
Activity: Even or odd
Write label(n) so it returns even or odd.