Skip to main content

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​

Quiz

if and else

1 / 2

If 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​

Quiz

if

1 / 2

What 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.