【发布时间】:2015-05-29 00:52:16
【问题描述】:
我的代码有问题,它说
TypeError: +: 'int' 和 '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,它们最初被解释为字符串 -
你能解释一下你想让它做什么吗?另外,您能否将代码减少到最少以显示错误?
-
我想要它,这样我就可以使用我的输入作为数字来计算总和
标签: python