Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community!

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

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,870 Points

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

1 Answer

Chris Freeman
Chris Freeman
Treehouse Moderator 68,404 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!!