I am trying to write a program that reads from a list a series of names and numbers like this:
5
Jim
79 84 82
Bob
32 12 47
Kelly
90 86 93
Courtney
80 99 89
Chad
89 78 91
The format for the numbers is:
<Assignment score> <Quiz Score> <Exam Score>
And the multipliers for each are:
.3 .1 .6
Currently I have this:
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()
My output should look like this:
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>.
But instead, I get this:
Kelly
's Score is <avg> %.
Any ideas on how to get the print to get every name in the file and every line of numbers in the file? Thanks in advance!
You need to strip the trailing newlines from the result of readline.
Maybe like this: