14/15 got 99 problems but a switch ain't one


#1

I've been stuck on this for a few days and I viewed other answers but none worked. If u think you know how to get past this one please let me know.

def greater_less_equal_5(answer):

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

print greater_less_equal_5(2)
print greater_less_equal_5(4)
print greater_less_equal_5(6)

Thank You!


#2

I have tried a number combinations. Could not get it to work should be simple being any number less than five should work.


#3

Here is what I did and it worked:

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

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

Best,

Diana


#4

Thank you so much, I was stuck on this for like 3 hours!


#5

I didn't really get the elif part... but oh well... Your answer worked.


#6

I appreciate the help Diana15...I was stuck on this for longer than i'd like to admit. Happy Coding!!


#7

Thanks so much it worked so well i was stuck on that for ages.


#8

I was stuck on this for three hours. Thanks everyone!


#9

may i suggest a new idea instead of copying others work to pass, kinda cheating yourself lol...

lets not forget we have a python interpreter that tells us what we are doing wrong. this is how i passed this part... i looked at the interpreter and did what it says. it gives you every detail of what is wrong in the code, starting from the top, to the bottom. it gives every specific line that the error is on, and then even points out what is wrong with a one of these ---> ^

try this little trick from now on and you will find every little detail of what you did wrong... part of learning is learning what you did wrong and figuring out on your own how to correct your mistakes... practice makes perfect :smiley: i hope this is useful to all that read it ;D


#10

hey, your code worked fine, can you explain why does it work cause i didn't understand


#11

thanks,it worked.very well