林和我的代碼有問題,它說類型錯誤:對於不支持+操作數類型(S):「詮釋」和「海峽」錯誤
TypeError: unsupported operand type(s) for +: 'int' and 'str'
,我不知道爲什麼。我的代碼導致這個區域如下所示,所有幫助將不勝感激:D!*編輯錯誤似乎發生,因爲輸入選項,如果這有助於任何方式。
Score1 = str(input("what did the first person get in their test the first time?"))
Score2 = str(input("what did the first person get in their test the second time?"))
Score3 = str(input("what did the first person get in their test the third time?"))
Score4 = str(input("what did the second person get in their test the first time?"))
Score5 = str(input("what did the second person get in their test the second time?"))
Score6 = str(input("what did the second person get in their test the third time?"))
Score7 = str(input("what did the third person get in their test the first time?"))
Score8 = str(input("what did the third person get in their test the second time?"))
Score9 = str(input("what did the third person get in their test the third time?"))
P1S = [Score1, Score2, Score3]
P2S = [Score4, Score5, Score6]
P3S = [Score7, Score8, Score9]
print ("here are the scores of",Name1,",well done") # defines scores
print(P1S)
print ("here is the average score of",Name1,",Well Done") # makes average of scores
print(sum(P1S)/float(len(P1S)))
print ("here are the scores of",Name2,",well done") # defines scores
print(P2S)
print ("here is the average score of",Name2,",Well Done") # makes average of scores
print(sum(P2S)/float(len(P2S)))
print ("here are the scores of",Name3,",well done") # defines scores
print(P3S)
print ("here is the average score of",Name3,",Well Done") # makes average of scores
print(sum(P3S)/float(len(P3S)))
我認爲你必須將'Score'輸入轉換爲int,它們最初被解釋爲字符串 – EdChum 2015-03-25 11:19:33
你能解釋一下你想要它做什麼嗎?另外,您是否可以減少代碼以最小化顯示錯誤? – 2015-03-25 11:20:01
我想要它,所以我可以使用我的輸入作爲數字工作到一個總和 – 2015-03-25 11:22:04