Function Review


#1

Here is my code and I am receiving an error that says "return outside function. Can anyone help?

Thanks

def shut_down(s):
return s

if s=='yes':
return "Shutting down"
elif s=='no':
return "Shutdown aborted"
else:
return 'Sorry'


#2

Function ends when It hits return statenent!
return s

This line is doing same thing, also Your if/else block should be inside the function!


#3

this works for me:

first declare the function

then ask for user input

call the function

print the result

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

confirm = input("Shutdown? yes/no ")
confirm = confirm.lower()
print(shut_down(confirm))


#4

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