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

Why does my function return True for even numbers?

有帮助吗?

解决方案

you need to change it to:

x = x % 2

to actually update the variable in line 2.

其他提示

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top