python
Making decisions
Programs make decisions with if:
age = 15
if age >= 18:
print("You can vote")
elif age >= 16:
print("You can learn to drive")
else:
print("Wait a little bit!")
To compare values:
| Code | Means |
|---|---|
a == b | equal (two =! one = is for variables) |
a != b | not equal |
a < b, a <= b | smaller, smaller or equal |
a > b, a >= b | bigger, bigger or equal |
Remember % from the maths exercise? n % 2 is the remainder when dividing by 2: it's 0 for even numbers.
Your mission
is_even(n)returnsTrueifnis even,Falseotherwise.describe_weather(temperature)returns:"cold"if the temperature is below 10"nice"from 10 to 25 (included)"hot"above 25