Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/329.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python TypeError:+;的操作数类型不受支持:';int';和';str';错误_Python - Fatal编程技术网

Python TypeError:+;的操作数类型不受支持:';int';和';str';错误

Python TypeError:+;的操作数类型不受支持:';int';和';str';错误,python,Python,我的代码有问题,它说 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

我的代码有问题,它说

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)))
您明确地注意用户输入的内容是字符串:

Score1 = str(input("what did the first person get in their test the first     time?"))

如果将
str()
替换为
int()
float()
(取决于您预期的输入),您的问题应该会消失,因为您会得到一个数字类型,而不是
str
ing。

将字符串默认输入转换为整数,以便您可以计算平均分数:

Score1 = int(input("what did the first person get in their test the first time?"))

您还可以在计算分数时使用map

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(map(int,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(map(int,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(map(int,P3S))/float(len(P3S)))

您还可以告诉我您是如何提供输入的。

我认为您必须将
分数
输入转换为int,它们最初被解释为字符串。您能解释一下您希望它做什么吗?另外,您能将代码缩减到最小以显示eror吗?我想要它,这样我就可以使用我的输入作为数字来处理sumI,现在可以对这个问题进行回溯(最后一次调用):文件“\\CUR-FSM\10brierleye$\Computing CA 2\task 3 average.py”,第57行,Stu3AVG=(sum(Score3)/float(len(Score3)))#定义平均TypeError:“int”对象不是iterablethat行不出现在您发布的代码中。实际上,您可以a)提出一个新问题,或者b)尝试了解错误的原因。编程就是要理解问题,而您目前所做的只是不断运行StackOverflow来报告错误。我建议你认真阅读错误。它确实说明了问题所在。我会尝试向您展示我的全部代码,但对于回复来说太长了,基本上我输入了一个名称和一些值来创建输入分数的平均值,将名称按字母顺序排序,并将平均值按从高到低的数字顺序排序,然而,它说输入的整数不可iterable,我也不知道为什么:李一直收到这样的信息:“int”对象不可iterable,你可以评分吗?发布您的更新代码以进行调试。您使用的是Python 2还是Python 3?Score7=int(输入(“第三人第一次在测试中得到了什么?”))Score8=int(输入(“第三人第二次在测试中得到了什么?”))Score9=int(输入(“第三人第三次在测试中得到了什么?”)P1S=[Score1,Score2,Score3]P2S=[Score4,Score5,Score6]P3S=[Score7,Score8,Score9]打印(“这里是”Name1“的分数,做得好”)#定义分数打印(P1S)打印(“这里是”Name1“的平均分数,做得好”)#使分数打印平均(总和(P1S)/浮点(len(P1S)))Python3.2我相信69我是通过手动输入提供输入的,尽管我将输入定义为一个整数(因为我需要在代码后面的等式中使用它),但我仍然得到Int是不可接受的问题行号是56,错误是INT不可iterable,我不知道为什么,因为当我设置值时它工作,但现在我以某种方式添加到输入值中,它被破坏了