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 trial

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,690 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