Hep with Review: Functions


#1

So I've been having some trouble with functions lately :disappointed:. And now i'm stuck..... again. Here's my code:

    def shut_down(s):
    if shut_down(s == "yes"):
        return "Shutting down"
    elif shut_down("no"):
        return "Shutdown aborted"
    
    else shut_down not ( "yes" or "no"):
        return "sorry"
        
        
shut_down("yes")

When I save and submitt my code, the error message says:

Oops, try again. Your code looks a bit off. Feel free to peek back at earlier exercises if you need a refresher! Your code threw the following error: invalid syntax (python, line 7)

The console says:

File "python", line 7
    else shut_down not ( "yes" or "no"):
                 ^
SyntaxError: invalid syntax

I don't understand. I thought I did everything the way I was told how to. Where did I mess up?

Thank you to dayfiri and papusalaatti for answering my question. Sorry for taking so long to respond..... this was the only way I could.
Thank you again!
`


#2

else doesn't take anything, only returns something when nothing before it is satisfied.

else:
  return "sorry"

You don't check it this way. You called function at the bottom of your code with value of "yes". That value is passed to s.
So you would check then:

if s == "yes":
  return "Shutting down"

#3

Also you must add four spaces before if statement like this:

def shut_down(s):
    if shut_down = stuff

Remember the whitespace!


#4

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