</>
Topic 3 of 10
Theory

Conditions

if runs code only when a condition is true. elif means "else if", else means "in every other case":

t = 25
if t > 30:
    print("Hot")
elif t > 15:
    print("Warm")
else:
    print("Cold")

Comparisons: == != < > <= >=. Combine conditions with and, or, not:

if age >= 7 and age < 18:
    print("Student")

Indentation (4 spaces) shows which code belongs to the condition.

Even or odd

Easy+10 XP

The parity function gets an integer. Return even or odd.

parity(4) → "even"
main.pyLoading Python…
Output
Press "Check" to run the tests