我在尝试将功能恢复到自身的开头时遇到了困难。我的代码是:
def questionFour():
print("")
global questionsCorrect
global questionsIncorrect
print ("What is 4 + 4?")
questionFour = input (">> ")
if str.isdigit(questionFour):
if questionFour.lower() == ("8"):
questionsCorrect += 1
questionFive()
else:
questionsIncorrect += 1
questionFive()
else:
print ("That's not a number!")
questionFour()
我遇到了这个问题:
Traceback (most recent call last):
File "[hidden]", line 330, in <module>
questionOne()
File "[hidden]", line 42, in questionOne
questionTwo()
File "[hidden]", line 53, in questionTwo
questionThree()
File "[hidden]", line 70, in questionThree
questionFour()
File "[hidden]", line 87, in questionFour
questionFour()
TypeError: 'str' object is not callable
谢谢!
答案 0 :(得分:5)
您使用第questionFour = input ...
行分配给questionFour。由于Python的作用域,这只会在函数内部保持正确,但会使您无法以递归方式调用它。为输入选择不同的变量名称。