Is_even


#1

I don't understand the following error message:

Oops, try again. is_even(39) raised the following error: 'type' object is not iterable

def is_even(X):
    for x in numbers:
        if x % 2 == 0:
            return True
        else:
            return False

I know something is missing but I don't know what I should add...

Can someone help me?


#2

First of all, there is no point for the "for" loop. The way you have it structured, you aren't even checking if the number you pass through is even. You are looping through all numbers in some array called numbers that is (as far as I know) undefined.

Corrected and cut down code:

def is_even(x):
    if x % 2 == 0:
        return True
    else:
        return False

So whatever number you pass through to is_even (the variable x) it will run the if/else with the modulo operator.


#3

Ok thank you

(it is more simple than what I thought)


#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.