S is not defined


#1

Hello,
Not sure what is happening here. I looked at a few articles and essentially made mine look identical and yet I still am receiving an error. I have s defined in the top line.


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

Traceback (most recent call last):
File "python", line 4, in
NameError: name 's' is not defined


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


#2

So first off, your return s isn't really doing anything here and it will mess up your if and else process when you try to run it. Yes I know the lesson example uses them but ignore that. It actually is a mistake to do that in this case.

Secondly, you don't need ( ) because you aren't using parameters in this lesson. Yes, I know the example uses them too but ignore that for the same reason as above.

Now what you are doing in your if else statement is like in step 3.) Alternatively, elif s is equal to "no", then the function should return "Shutdown aborted". Please notice return!


#3

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