Conditional and control flow


#1

hello, my friends. I'M STUCK on conditionals since 2014 !! woww It's true that I had never asked for help but that's the moment...

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

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 0 when answer is 5. Make sure you filled in the if and elif statements correctly!

-1
-1
-1
None


#2

Hi @codewhiz71790,

Hmmm... that's a long time. Glad you are being persistent. :smile:

If you format your code when you post it, it will be easier for us to read it. After code has been pasted into the editing window for posting, you can format it by selecting it, and then by clicking the </> button above the editing area. Alternatively, you can place three backquotes on the line before the code and three backquotes on the line after the code. This will enable us to see important details, such as the indentation and underscores. If you use the backquotes, your code will be color-coded, making it especially easy to read.

Your function has a parameter, answer, and that is what you need to compare to 5. You also need to return either 1, 0, or -1, based on the outcome of that comparison.

For example, instead of ...

if 4 > 5:
    return 5

... you need to have this ...

if answer > 5:
    return 1

See if you can pattern the remainder of the if structure after the above.


#3

Hey you do not have to be stuck anymore. You are not suppose to write the answers rather you just right the word answer

that means it should look like the following:

def greater_less_equal_5(answer):
if answer > 5:
return 1
elif answer < 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

Oh, mY Goshhh , I'm freak relief. Thank you all. It's so good, and that's why it worths a lot!!