Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.
Divisible by 2?
I don't understand what they mean by create a function that returns TRUE not divisible by 2?
Chris FreemanTreehouse Moderator 67,638 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!!