Hi all, am having some serious issues working around the "if" function in python.Please help!


#1


Instructions
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.
?
python
def greater_less_equal_5(answer):
    if ________:         ....................(line 2)
        return 1
    elif ________:   ......................(line 4)          
        return -1
    else:
        return 0
        
print greater_less_equal_5(4)
print greater_less_equal_5(5)
print greater_less_equal_5(6)


#2

Okay, show us what you've tried, so we guide you way-up. :slight_smile:


#3

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

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


#4

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 4)
not too sure what to do again cos i have tried other methods buts its not working


#5

Okay. Thank you for providing all these.

Now, the first (line 2) is to check if answer is greater than 5. So, you should be using your parameter, answer and not the function again.

You do:

if answer > 5:

Follow this trend through.

I hope this helps! :slight_smile:


#6

wow thanks a lot ... i did work!!


#7

You're welcome.

Have fun coding! :slight_smile:


#8

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