Python Practice Creating and Using Functions in Python Practice Functions That's Odd

Divisible by 2?

I don't understand what they mean by create a function that returns TRUE not divisible by 2?

Dave StSomeWhere
Dave StSomeWhere
19,802 Points

Check out % modulus - that should point you in the right direction.

1 Answer

Chris Freeman
Chris Freeman
Treehouse Moderator 59,597 Points

There are two steps to returning a Boolean True or False result

  • establish which value to return. For example result = value > 5 to find if value is greater than 5
  • return the value. For example return value

These could also be combined using return value > 5. The full python code would look similar to:

def greater_than_five(value):
     return value > 5

To find you if something is divisible by 2, you can check if there is no remainder from value // 2 or use the modulo 2 syntax: value % 2 which returns a 0 if it is divisible by 2. Be careful not to simply return the 0 result, as 0 is considered "False". Hint how can you turn the "False" value of 0 into a "Truthy" value?

Post back if you need more help. Good Luck!!