我正在尝试编写一个程序,该程序从列表中读取一系列名称和数字,如下所示:
5
Jim
79 84 82
Bob
32 12 47
Kelly
90 86 93
Courtney
80 99 89
Chad
89 78 91
数字的格式是:
<Assignment score> <Quiz Score> <Exam Score>
每个乘数是:
.3 .1 .6
目前我有这个:
def main():
inFile = open("input.txt","r")
numVals = int(inFile.readline())
for i in range(numVals):
name = inFile.readline()
numbers = inFile.readline().split()
for n in range(len(numbers)):
numbers[n] = float(int(numbers[n]))
avg = float(numbers[0]* .3 + numbers[1]* .1 + numbers[2]* .6)
print(name, "'s Score is",avg,"%.")
inFile.close()
main()
我的输出应该是这样的:
Jim’s score is <avg>.
Bob’s score is <avg>.
Kelly’s score is <avg>.
Courtney’s score is <avg>.
Chad’s score is <avg>.
但相反,我得到了这个:
Kelly
's Score is <avg> %.
关于如何打印以获取文件中的每个名称和文件中的每一行数字的任何想法?提前致谢!