当我试图调用一个函数时,我得到了#34; TypeError:' str'对象不可调用"

时间:2018-01-03 04:01:12

标签: python

在搜索多个论坛后,我仍然无法找到我理解的答案。我正在制作一个简单的文字游戏,当写下它的一部分时,我得到了这个:" TypeError:' str'对象不可调用。"。下面是代码:

def tutorial():
    print ("In this game your objective is to make out alive from the haunted house of torture.")
    print ("In each round, you will be faced with 3 questions, 3 choices each question.")
    print ("Now, are you ready to begin? (Yes or No)")
    begin = input()
    if begin == "No":
        def redo():
            print ("Oh, than would you like to start the tutorial all over again?(Yes or No)")
            stog = input()
            if stog == "No":
                redo()
            if stog == "Yes":
                tutorial()

def start():
    print ("Hello! Would you like to start the tutorial? (Yes or No)")
    tutorial = input()
    if tutorial == "No":
        print ("Okay than, lets begin!!")
        start()
    if tutorial == "Yes":
        print ("Okay than, lets start the tutorial!!")
        tutorial()

start()

我得到的确切错误信息是:

Traceback (most recent call last):
  File "C:\Users\jeff\AppData\Local\Programs\Python\Python36-32\tester2.py", line 29, in <module>
    start()
  File "C:\Users\jeff\AppData\Local\Programs\Python\Python36-32\tester2.py", line 23, in start
    tutorial()
TypeError: 'str' object is not callable

说完&#34;是&#34;后我得到错误第一个问题。非常感谢,谢谢。

1 个答案:

答案 0 :(得分:1)

def start():
    print ("Hello! Would you like to start the tutorial? (Yes or No)")
    tutorial = input() #warning, a bad variable name, same with outer 
                       #function, will overwrite the name.
    if tutorial == "No":
        print ("Okay than, lets begin!!")
        start()
    if tutorial == "Yes":
        print ("Okay than, lets start the tutorial!!")
        tutorial()  # error, tutorial is a string now, it is not callable