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


#1
def greater_less_equal_5(answer):
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)

I still can't get it right


#2

look at this code:

# function declaration 
def greater_less_equal_5(answer):
   print answer

# function calls
print greater_less_equal_5(4)
print greater_less_equal_5(5)
print greater_less_equal_5(6)

see how when we call the function, our argument (4, 5 and 6) get copied into the function parameter answer?

So it would make sense to do the comparison of in the if/elif statement using answer, this way, we can call our function with any number, and the function will tell us if the number is greater, smaller or equal to 5.


#3

It took me a little while to get it, even after reading the reply from @stetim94 but I finally got there

It's looking to check the (answer) against 5. Not whether 6 > 5 or 4 < 5. I hope this helps.


#4

that was kind of the idea of my reply, i wanted you to realize what needed to be done, i just wanted to push you in the right direction.

by comparing with answer, we can pass any number as argument when calling the function, and it will tell us whether this number is greater, smaller or equal to 5


#5

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