I Got 99 Problems, But a Switch Ain't One


#1

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)

I tipe this and then:Oops, try again. Your code looks a bit off. Check the Hint if you need help! Your code threw the following error: invalid syntax (python, line 2) comes out. What to do?


#2

Well if this is an exact copying of your code you forgot to indent your lines for if elif and else statements along with their returns. For example this should how your middle code should look with correct spacing:

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

#3

Thank you.
This has help me.
I was stuck on this for long time.


#4

Glad to help! I have been there and that is no fun being stuck. Happy coding! :smiley:


#5

@bibleman13

I disagree :slight_smile:.....I find the fun in trying to find new ways to figure out problems.


#7

Well I would agree but after being stuck on a problem for a few days, week, month...it can get old really quick and if you run out of ideas it can be a determinate to your learning and many people quite just because of they get stuck and don't have anywhere to turn to get answers. That is why I love the forums so much and have spent so much time on them :smiley: Its people helping other people get better. So while I like a good challenge every day even, being just dead lost on a lesson or something else is no fun lol flash backs to math classes


#8

He says while I'm sitting in math class trying to cram study for a test I have. :confounded: :joy:


#9

Well, I can't time it any better than that lol I know your pain :joy: :cry: I will do my college algebra homework in your honor :stuck_out_tongue:


#10

It seem like the same thing you typed, but I get:
"Oops, try again. It looks like your function output 1 instead of -1 when answer is 3. Make sure you filled in the if and elif statements correctly!"

which seems wrong because if "answer" == 3 then "answer" < 5 there should give -1, no?

Any help appreciated!


#11

@blogjumper73520,
Next time, post your issue in a new thread.

The problem is that you put quotes around answer.
This turned answer into a string instead of accessing its value. :slight_smile:


#12

Oh, right. Thank you.


#13

Welcome! :slight_smile:


#14

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