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


#1

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

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

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!

What is the problem?


#2

you want to see if answer (the function parameter) is greater, smaller or equals 5. use answer correctly in the if/elif condition


#3

How can I do that :-Q


#4

Hi,

you can put the variable in the comparisson:

if answer < 5:
    print("answer is smaller than 5")

#5

Can you please elaborate? No matter what I do, it keeps print 1 instead of -1


#6

Can you show us your code?


#8

I was thinking about it too literally.
I was keying in if 5>1
1>5

when the answer was already set to be defined


#11

answer is a variable, so you can just compare it with 5:

answer > 5

#12

How is print towards the end of the program helping set the variable to 4 or 5 or 6; I am totally missing this !

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

Thanks in advance,


#13

you call the function here:

print greater_less_equal_5(4)

you pass an argument (4) into the function, so the function parameter will now hold the value passed by the function call


#14

Thanks a bunch, somewhat clear. Guess will take some more practice to grasp the details.


#15

look:

def example(parameter):
   print parameter
example("see how the parameter is a place holder for the value past into the function call")

hopes that helps


#16

Yes thank you, this helps.


#17

Thanks for your comment. Helped me figure it out.


#18

it says I have to have a number.


#19

if you have a question, make a new topic, don't clutter a topic, topics are actually only to help the person who original created the topic


#20

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