Lesson 14 (conditionals % control flow)


#1

This is my code.

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

What am I doing wrong here? This lesson is confusing me quite a bit.

#2

What is your error message?

I'm assuming that it wants you to do something like

if answer>5:

and

elif answer<5:

#3

@arizeto ,

(EDIT: @kyleaw replied with sage advice while I was composing my post. See the above.)

The function parameter is answer. For this exercise, the code within the greater_less_equal_5 function definition needs to compare the value of answer to 5, rather than compare a constant to 5.

However, you have conditional headers such as this within the function ...

if 6>5:

Instead of comparing 6 to 5, compare answer to 5. The elif condition needs to be modified similarly.


#4

Thanks guys. I somehow missed the answer parameter and confused myself quite a bit.


#5

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