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! While you're at it, check out some resources Treehouse students have shared here.
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 trialBrian S.
3,176 PointsHmmm... any suggestions? Code is doing as I expect, still not getting answer correct.
i also tried altering the Else to: else num % > 0 : print('False') break
def even_odd(num):
while True:
if num % 2 == 0:
print('True')
break
else:
print('False')
break
2 Answers
zy93
Python Web Development Techdegree Student 6,879 PointsHey there!
1) Remove the loop and "break" statements-- You don't need to check if a number is odd or even more than once
2) Don't print true or false, use return instead :D -- This is how you get the value out of the function for reuse, rather than just showing the answer on the screen.
Your use of the modulo function is spot on though!
Kristian Gausel
14,661 PointsI dont understand why you use a loop. Also it says you should return true or false, not print it. The code looks something like
def even_odd(num):
return num % 2 == 0
Brian S.
3,176 PointsI dont understand why i used a loop either, in hindsight. Thank you
Brian S.
3,176 PointsBrian S.
3,176 Pointswow, i was doing way too much. Thank you