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
Divisible by 2?
I don't understand what they mean by create a function that returns TRUE not divisible by 2?
Chris FreemanTreehouse Moderator 68,404 Points
There are two steps to returning a Boolean
- establish which value to return. For example
result = value > 5to find if value is greater than 5
- return the value. For example
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!!