Damian McCarthy3,656 Points
I have no idea how to even think about this one.
I don't know where to start.
def even_odd() if a%2: return True else: return False
AJ Salmon5,674 Points
You're on the right track. First, though, you need to make sure that your function takes an argument, so you give it a placeholder argument when you create it. This is called setting the parameters, and it looks like this:
def even_odds(num): #you can name this placeholder anything you want, #it's just somewhat conventional to use 'num' when #you know that the argument will be a number
On a side note, if your function needed to take two arguments, for example, you'd set two parameter arguments, like this:
def add(num1, num2):
Alright, now we need to test and see if this number has a remainder when it's divided by 2. As the challenge mentions, you can use the
% opperand to do this. If
num % 2 is equal (or
== in python) to 0, then it's even, and you need to
return True. Otherwise,
return False. I know you can do the rest by yourself, happy coding, and if you need any more guidance feel free to ask! :)
Aayush Mitra24,362 Points
You have three errors in your code.
First of all when after you define your function, you need to add a colon. Like this:
def even_odd(): #add colon
Second, you need to give it an argument called "number" as it says to do in the challenge. Like so:
def even_odd(number): #add argument number
Finally, in your if statement, the first block of code is supposed to say that when the number, passed in by the user, is divided by two, the remainder will be 0, because that makes it an even number.
We can do this by using the modulo operator: %. If we say:
if number % 2 == 0:
Other than that your code is fine.
Here is the final code:
def even_odd(number): if number % 2 == 0: return True else: return False
Hope this works!
If this does not, please let me know.