0

所以,我是 Python 的新手。

我们已经开始在学校报道它,我遇到了一些问题。

我正在尝试使用积分系统在 python 中创建一个测验。积分系统适用于前两个问题,但是当它到达第三个问题时,我总是收到以下错误:

 Traceback (most recent call last):
 File "C:\Python33\ICT kat.py", line 63, in <module>
 print(" You have " + str(score) + " points so far!")
 TypeError: 'str' object is not callable

以下是错误似乎来自的编码:

 print("Question 3:")# This the third question in the quiz
 print(my_name + ", What is the total amount of days in February + March + June in a    leap year.")
 qu3_ans = input()# This is where the user would input their answer
 if qu3_ans == "90":# This is the answer to the question
 print("Good job! + 1 point")#If the user gives the correct answer this is displayed
 score = score + 1 #This is the points system

  else:
  print("That was the wrong answer! :(")#If the user gets anything other than 90 this  will be displayed
  print("No point for you! ^_^")# "  "

  print=(" ") #Used like the enter key in a word processing progra,

  print(" You have " + str(score) + " points so far!")#This is where the errors occurs,     and is used to displayed the current amount of points
4

1 回答 1

3

看起来您已在str某处用作变量,请不要这样做:

>>> str(1)
'1'
>>> str = "foo"
>>> str(1)
Traceback (most recent call last):
  File "<ipython-input-63-dd09b06c39ba>", line 1, in <module>
    str(1)
TypeError: 'str' object is not callable

您可以使用字符串格式,而不是使用字符串连接:

print(" You have {} points so far!".format(score))
于 2013-06-27T14:37:28.097 回答