Still unable to get it right


#1

I have read it many times but is still unable to get it right.
I wrote:
def greater_less_equal_5(answer):
if (8 - 2) < 5:
return 1
elif (8 - 2) > 5:
return -1
else:
return 0

and got the error message:
It looks like your function output -1 instead of 0 when answer is 5.
Make sure you filled in the if and elif statements correctly!

Which part am i not getting right?


Help with 99 problems, switch ain't one
#2

It took me a while to realize what I was doing wrong thanks to mtf and I see the same problem in your code.
I just started learning so I dont know all the technical terms, but basically you should be using "answer" instead of anything else to compare to 5...your code here:
def greater_less_equal_5(answer):
if (8 - 2) < 5:
return 1
elif (8 - 2) > 5:
return -1
else:
return 0

is correct except for the characters in the if, elif, else statement. i.e:
if answer < 5:
return 1
elif answer > 5:
return -1
else:
return 0

Basically what we were all trying to do is to make a number to compare to 5, instead of using the number (answer) that they gave us in the first line. Hope that helps.


#3

Thank you webmaster22952 for pointing out that we need to compare to the "answer" and for the clear illustration. I got it now. Thanks :slight_smile:


#4

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