2013-06-27 43 views
0

所以,我是Python的新手。無法修復這個惱人的錯誤! :L

我們已經開始在學校覆蓋它,我有一些問題。

我試圖在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 
+5

聽起來像你已經在代碼中的其他地方使用'str'作爲變量名。 – Aya

+1

您可以將您最後的'print'語句更改爲以下打印(「您有」,得分,「到目前爲止!」)。 – Sam

+1

另外(因爲這是Python)確保你正確地縮進你的代碼。 – iamnotmaynard

回答

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 

使用字符串連接可以使用string formatting相反的:

print(" You have {} points so far!".format(score))