Question

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

Why does my function return True for even numbers?

Was it helpful?

Solution

you need to change it to:

x = x % 2

to actually update the variable in line 2.

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top