17 Review Syntax Error


#1

Here is my code and the error is get is file python line 4 Syntax error: 'return' outside of function
I don't know what this means and I have tried deleting 'return s' and then it gives me an indentation error.

def shut_down(s):
    return s
if s == 'yes':
    return 'Shutting down'  <--- Here is line 4 
elif s == 'no':
    return 'Shutdown aborted'
elif s != 'yes' or 'no':
    return 'Sorry'

#2

Before offering a blunt solution, may I suggest you study your code closely and look for any scope issues. What do you find?

For starters, return s is not part of the solution.


#3

I deleted the 'return s' and indented the if statements and it worked ! Thanks!


#4

Before I delete the 'return s', there is a error showing ' 'return' outside function' when running the program. I did almost the same except the second "elif". I wrote "else: return 'Sorry' ".


#5

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

return s  # example of 'return outside function

The last line is not part of the solution, which is above it (yours should look similar). Just for eg.


#6

OK. I knew the mistakes in my code. Thank you! I figured it out.