Need help with this line? I am not getting whats wrong?

#1

if 6 > 5:
return 1
elif 4 - 5:
return -1
else:
return 0

print greater_less_equal_5(4)
print greater_less_equal_5(5)
print greater_less_equal_5(6)

#2

Instead of using fixed numbers like 6 and 4 you should use the variable 'answer'

#3

@nmegabyte The problem in your code is that you used the parameter "answer" in your function, but you never used the actual variable in your code, so every time you do this:

It's useless because "answer" is never used, therefore the function never really takes in account the answers you gave it.

Also:

``````if 6 > 5:
return 1
elif 4 - 5:
return -1
else:
return 0``````

I'm quite confused how you expect your code to work if you have the values set into place already. The first if statement will always print because it is always true. Your function is suppose to be made so that is varies each time for each value of "answer". I'm assuming you were trying to achieve this:

``````def greater_less_equal_5(answer):
if answer > 5:
return 1
elif answer < 5:
return -1
else:
return 0``````

Or this code:

``````def greater_less_equal_5(answer):
if  5 + 1 == answer:
return 1
elif answer + 1 == 5:
return -1
else:
return 0``````

This should fix your code although I am unclear what exercise it is from, so I don't know if either code will actually fit the instructions. Let me know if you still need more help after this.

#4

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