Functions Review: Functions


#1



Functions
Review: Functions


File "python", line 2
if s == "yes"
^
SyntaxError: invalid syntax

what's wrong with the code?

def shut_down(s):
    if s == "yes"
        return "shutting down"
    elif s == "no"
        return "shutdown aborted"
    else 
        return "sorry"


#2

Missing colon signs at the end of your if/elif/else.


#3

Did you forget the colons on the end of your if,elif statements?


#4

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


#5

you forget the two points


#6

what could be wrong?

def shut_down(s):
return s
if s == (yes):
return "Shutting down"
elif s == (No):
return "Shutdown aborted"
else:
return "Sorry"
Oops, try again. Your function failed on the message yes. It returned 'yes' when it should have returned 'Shutting down'


#7

You have parenthesis around "yes" and "no" in you code in these lines:

They should have quotes around them instead, as they are both suppose to be strings. Assuming your indents are correct, you should be good then.

Hope that helps! :slight_smile:

-- @chipjumper36731


#8

this is my code
def shut_down(s):
return s
if s == "yes"():
return "Shutting down"
elif s == "No"():
return "Shutdown aborted"
else:
return "Sorry"

It saying that
File "python", line 4
SyntaxError: 'return' outside function
i even had the no and yes without the () after them and it still said the same thing. I have written something different
def shut_down(s):
return s
if "yes":
return "Shutting down"
elif "No":
return "Shutdown aborted"
else:
return "Sorry"

it still says the same thing. Thanks in advance.


#10

Your first code was closer to corect. It should be like this:

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

Remove this lines from your first attempt and you should be good:

Hope that helps! :slight_smile: Message me if you still need more help.

-- @chipjumper36731


#11

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