17/19 Cannot identify error


#1

For the life of me i cannot pass the function review section, I just cant identify my error in the following code, apparently there is a syntax error on the 2nd last line. Could someone please give this a look?
Many thanks.

def shut_down(s):
return s

if s == 'yes':
    return 'Shutting Down'
elif s == 'no':
    return 'Shutdown Aborted'
else s == 'yes' or 'no':
    return 'Sorry'

#2

The last ELSE is what the program does if the IF or ELIF conditions are not met. You don't have to give it condition "else s == 'yes' or 'no'" because that's obviously true else the program wouldn't have gotten to that point and would have just returned "Shutting down" or "Shutdown aborted"

Think of it as a tree.

IF "CONDITION1" > DO THIS > END
v
ELSE IF "CONDITION2" > DO THIS > END
v
ELSE > DO THIS > END

Notice if it gets to ELSE there is no condition for it, It just does stuff if IF or ELSE IF conditions aren't met.


#3

you could also put another elif there, instead of an else (but I wouldn't recommend that in this case :slightly_smiling: ), but I think you wanted to check else s != 'yes' or 'no', because you want to check if it's neither of them (otherwise it would do the same check as the if and elif above :smiley: .

You could also try:

if s == 'yes':
    return 'Shutting Down'
elif s == 'no':
    return 'Shutdown Aborted'
elif s != 'yes' or 'no':
    return 'Sorry'

If you want to do it with else, you should consider the way gsergiu told you, to use "else" properly :slightly_smiling: