i am writing a program that reads the file i create. The file has grades and weights of grades anddd 3 person but i need to create a program that will read the information from the file, calculate and print the total average of each student given by the formula wn*gn/100 and then totals the average of all grades. my file looks like
FirstName lastName w1 g1 w2 g2 w3 g3 w4 g4
Billy Bother 20 89 30 94 50 82
Hermione Heffalumo 40 93 60 97
Kurt Kidd 20 88 30 82 40 76 10 99
and so far i did
import math
FileName = input("Enter the name of the file")
infile = open("grades.txt","r")
contents = infile.read()
lines = contents.split("\n")
sum = 0
for i in range(0,len(lines)):
line = lines[i]
words = line.split(" ")
sum = sum+(words[0])
avg =((wn+gn)/100)
print(sum/len(lines))
print(avg)
total_avg = 0
for i in range(3):
total_avg = avg[i]
total_avg= total_avg + avg[i]
print("total_avg", total_avg)
but doesnt work :/
the out put should be somethin like this
Billy Bother's average: 87.0
Hermione Heffalump's average: 95.4
Kurt Kidd's average: 82.5
Class average: 88.3
THANKS !