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

andrea riccio
andrea riccio
831 Points

even_odd didn't return the correct answer

I don't understand what is wrong... please help me

even.py
import random
def even_odd(x):
    x = random.randint(1,10)
    x = x % 2
    if x == 1:
        return True
    else:
        return False

2 Answers

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there! First, the challenge does not require you to import random nor use random in any way. Treehouse is going to send in a number that will be assigned to x as you have named it. You have overwritten what Treehouse has sent in twice. Once by assigning a random number to x. And once by taking the moderator of x and 2 and assigning it back into x. Also, there is a problem with your logic. A number that is even will have a remainder of 0, not 1. Your code should return Trueif the value is even and False if the value is 1.

This is how I did it:

def even_odd(x):
    #if the remainder is 0(even) return True else return False
    return x % 2 == 0

Going forward, try not to do anything the challenges don't explicitly ask for. Also, if you think you're overthinking the challenge, you're probably correct :sparkles: