17 - Review Functions - TypeError: 'str' object is not callable


#1



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


I'm getting the following error - but everything looks right (I know we all say that)

Traceback (most recent call last):
File "python", line 13, in
File "python", line 2, in shut_down
TypeError: 'str' object is not callable

What is this error - 'str' object not callable within the context of this function? I've reviewed on stack exchange but didn't see anything that really applied to this function.


def shut_down(s):
    if s == "yes"():
        return "Shutting down"

    elif s == "no"():
        return "Shut down aborted"
    
    else:
        return "Sorry"
        
s = raw_input("Do you want to shut down? Enter yes or no.").lower()
str(s)
print shut_down(s)


#2

here:

"yes"()

this is a function call because of the parentheses, the error message tells you strings can't be function calls (are not callable)


#3

This looks like a function call. Hence, str is not callable. Remove the ().


#4

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