我是
Python的新手,我现在仍然坚持做什么,因为我一直收到这个错误.我试图将得分文件的内容添加到一起并获得平均值,但我似乎无法让它工作.
我的代码:
# open and read file student / score
student_file = open("Student.txt", "r")
score_file = open("Score.txt", "r")
student = student_file.read().split(' ')
score = score_file.read().split(' ')
addedScore = 0.0
average = 0.0
for i in range(0,len(student)):
print("Student: "+student[i]+" Final: "+score[i])
addedScore = addedScore + score[i]
average = addedScore / 2
print("The class average is:", average)
分数文件充满了浮点数:
90.0 94.0 74.4 63.2 79.4 87.6 67.7 78.1 95.8 82.1
错误消息
line 12, in
addedScore = addedScore + score[i]
TypeError: unsupported operand type(s) for +: 'float' and 'str'
我很感激能得到的所有帮助.非常感谢