Greater_less_equal_5


#1

did any one solve this?

def greater_less_equal_5(answer):
if ___:
return 1
## elif ___:
## return -1
else:
return 0

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

=========
On line 2, fill in the if statement to check if answer is greater than 5.
On line 4, fill in the elif so that the function outputs -1 if answer is less than 5.


Greater/less/equal to 5
#2

EDITED on November 28, 2016 to add the following general information:

This discussion thread pertains to Exercise 14. I Got 99 Problems, But a Switch Ain't One.

As noted in several replies that follow, the parameter of the greater_less_equal function is a variable named answer. That variable is what needs to be compared to 5.



Hi, @vijay2017 ,

In answer to your question, give this a try, and if any problems occur, let us know.

For the if condition, consider what test would determine whether the value of answer is greater than 5. Replace the ___ with that comparison.

Use a similar approach to the elif condition.


#3

thank you for response

def greater_less_equal_5(answer):
if 5 + 6:
return 1
elif 5 -6:
return -1
else:
return 0

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

wondering why I got this

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!


#4

The function parameter is answer, and that is what we need to compare to 5.

You have ...

if 5 + 6:

... but what we really need to determine there is whether answer is greater than 5.


#5

not clear about this


#6

Would this work, regarding the if condition? ...

if answer > 5:

What would be an appropriate elif condition?


#7

thank you for correcting me. Its worked. I am silly

the o/p is
-1
0
1


#8

I can't solve the elif problem ... Anyone can help ? please give an example..


#9

Hi, @sakibkaiser ,

Post what you have for the if header, then we can think about how that relates to the elif header.


#10

okay . I use 6>5 for the if header.. and pls give an explanation how it actually works..


#11

That will not work. The function should not only be able to compare 6 to 5. It should compare the value of its parameter, answer, to 5, so that whatever int is passed to the function will be compared to 5.


#12

Can you please specify you solution?


#13

Hi Applypye,
I am stuck with the same problem, I have looked at all the answers in this conversatioin and tried but still can't get though. I appreciate your help,
Thanks in advance
This is what I get
def greater_less_equal_5(answer):
if 4 + 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)
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!


#14

Hi, @naicoding ,

You have ...

if 4 + 5:

However, what you actually need to with the if condition is determine whether the value of the variable, answer, is greater than 5.

Review the exercise instructions and apply similar reasoning to the elif condition.


#15

Thank you appylpye, that was very helful!


#16