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.

Python Python Basics (2015) Number Game App Even or Odd

kevin burns
kevin burns
2,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')
        if  not num %2 == 0 : 
            return False 
        print ("odd")

3 Answers

Sean T. Unwin
Sean T. Unwin
28,660 Points

Hi 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
kevin burns
2,570 Points

thank you .. great response and great answers ....

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