I don't understand why my code does not work, it looks correct to me?


#1


This is the code I am trying to run:

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

https://www.codecademy.com/courses/python-beginner-c7VZg/4/1?curriculum_id=4f89dab3d788890003000096

It gives an invalid syntax error message

I was expecting for me to get a a prompt to type so it will go through the If, elif, else loop.


Replace this line with your code.


#2

Is there a reason for the immediate return(s) statement?

In truth, we saw this exact code last week. Are you sure you wouldn't be up to just starting the whole thing over, reading from the instructions each step, one at a time?


#3

well its very small piece of code, sure I can rewrite it but I don't really understand what is it that's wrong with it? Why can I not have a return function in there?


#4

isn't all I am doing is creating an if statement with several options, if this return this, elseif this return that, etc??


#5

The immediate return means none of the code runs. It just returns s, the same parameter it is passed. That line needs to be removed so the if statement executes. There are other problems that we will soon discover.


#6

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