Why code is not working?


#1

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


#2

If your code is indented like that in the main code editor then the problem is your indentation,

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

should be,

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

But the main problem is this return statement,

remove it from your code because a return statement can only be inside an if/elif/or else statement. :slight_smile:


#3

Thank you .
I correct it and its working. :slight_smile:


#4

You're welcome also take a look at this post,


#5

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