I'm fairly new to python so bare with me. I'm trying to write a script that would calculate my class average from exams. The script will look at a text file formatted like this:
Calculus 95 90 92
Physics 80 85 92
History 90 82 83 95
The output should look like this:
Calculus 92.33
Physics 85.66
History 87.5
I have the following code:
#!/usr/bin/python
import math
f = open('exams',"r")
l = f.readline()
while l :
l = l.split(None,10)
L = l[1:]
print l[:1]
print L
print 'Number of Values ', len(L)
l = f.readline()
The code above pretty much takes each row and turns it into an array. The L variable determines how many grades are in (doesn't look for the subject). I planned on summing the grades and dividing by 'L.' Another problem is that when the text is in the array, it's handled as a string and not as integers/floats.
Anyone have any suggestions?