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.

kevin burns
2,570 Pointseven .. need some help please
maybe I'm missing something to the code...
import random
def even_odd (num):
while True:
num = random.random.int(1,20)
if num %2 == 0 :
return Trueprint ('even')
else:
if not num %2 == 0 :
return False
break
print ("odd")
3 Answers

Sean T. Unwin
28,660 PointsHi Kevin,
I believe you could be over-thinking this Challenge.
1) We don't need to import random
as a number should be passed to the function.
2) We don't need to print
anything since the Challenge does not request us to do so.
If we understand what the modulus operator does, particularly in relation to comparing num % 2
, then we really only need to return the result of that statement. This is because we will get a result of either True
or False
.
Therefore, this Challenge could be completed successfully with one-line inside the function.
I hope this helps.

kevin burns
2,570 Pointsthank you .. great response and great answers ....

TUNDE OLUSEGUN
Courses Plus Student 1,044 PointsHello Kelvin.. You have an idea and very close. Your code should be like this.
def even_odd(number): if number % 2 == 0: return True else: return False