>_Code Club
← All exercises

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:

CodeMeans
a == bequal (two =! one = is for variables)
a != bnot equal
a < b, a <= bsmaller, smaller or equal
a > b, a >= bbigger, 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

  1. is_even(n) returns True if n is even, False otherwise.
  2. describe_weather(temperature) returns:
    • "cold" if the temperature is below 10
    • "nice" from 10 to 25 (included)
    • "hot" above 25
Next exerciseLoops →
Loading the editor…