Question

def odd(x):
    x % 2
    return x > 0

Why does my function return True for even numbers?

Était-ce utile?

La solution

you need to change it to:

x = x % 2

to actually update the variable in line 2.

Autres conseils

It isn't working as expected because you are returning "is x greater than 0?" Try with x = -1 and you will see that this is false. The x % 2 part is not doing anything.

I would recommend taking an online course like udacity.com 's intro to computer science to get a better grasp of how basic programming works.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top