문제

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