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 burns2,570 Points
even .. 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")
Sean T. Unwin28,660 Points
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
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
Therefore, this Challenge could be completed successfully with one-line inside the function.
I hope this helps.
Hello 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