โ ๐ Python World
๐ Even or Odd?
You can practise without a player, but pick a player to score points!
๐ The mission
Today you unlock
If statements choose a path
An if statement checks a condition and chooses which answer to return. Order matters: check the special cases first.
๐ก Hint ladder
- n % 2 gives the remainder when dividing by 2.
- if n % 2 == 0: return "even"
๐งช Coach checks
- โฏ 4 is even
- โฏ 7 is odd
- โฏ 0 is even
- โฏ 99 is odd
Live coach
Getting ready
โโโ
๐ฌ % gives the remainder. Even numbers have remainder 0 when divided by 2.
print(4 % 2) # 0 (even)
print(7 % 2) # 1 (odd)
def is_zero(n):
if n == 0:
return "yes"
return "no"
print(is_zero(0)) # yes
๐ It printed:
Nice โ you saw it work!
๐ Output
๐งฉ Gaps filled! Ready to write it all yourself?