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

Spencer Heflin
Spencer Heflin
Pro Student 6,096 Points

Even or Odd Code Challenge

I'm not sure what I'm doing wrong on this one, so any help would be awesome. I keep getting a syntax error for even_odd%2 when I'm trying to get the remainder. I feel like I'm on the right track, but I'm clearly messing something up. Thanks.
even_odd = random.randint()

if even_odd%2 = 0:
    return True
    return False

2 Answers

AJ Salmon
AJ Salmon
5,674 Points

Hi Spencer,

You need to be creating a function for this challenge. It should start like this:

def even_odd(num):

Then you can check if the number is even or odd inside the function, so that when it is called later on and passed an argument, it will return True if it's even and False if it's odd. You were on the right track with your if statement, and you will need to use an if/else block inside the function. Side note: you don't need to use random.randint() in this challenge, but if you did, you'd need to import the random library first. Happy coding!

You need a range for your randint argument. Forexample, randint(min, max)