I'm a Python beginner trying write a program that reads outside txt files,
takes the data like the name and test grades of students then calculate the
average and also assigns a grade and writes the data into a new txt file.
I'm having difficulties writing the program so far I've been able to write
up half of the program but I am noticing there might be bugs. I've tried
running the program but every time I do, my program output is blank and
there is no error messages
here is the program
def calcaverage(test1,test2,test3):
for count in range(line):
curraverage=0
curraverage=((test1[count]+ test2[count]+ test3[count])/3)
currentaverage.append(curraverage)
if curraverage>= 90:
grade= "A"
lettergrades.append(grade)
else:
if curraverage >= 80 and curraverage < 90:
grade= "B"
lettergrades.append(grade)
else:
if curraverage >= 70 and curraverage < 80:
grade= "C"
lettergrades.append(grade)
else:
if curraverage < 70:
grade= "F"
lettergrades.append(grade)
name=[]
test1=[]
test2=[]
test3=[]
averagescore=[]
lettergrades=[]
with open ('/period1.txt', 'r') as infile:
line = infile.readline()
while line in infile:
values = line.split()
name.append(values[0] + ','+ values[1])
while line in infile:
values = line.split()
score1=float(value[2])
test1.append(score1)
while line in infile:
values = line.split()
score2=float(value[3])
test2.append(score2)
while line in infile:
values = line.split()
score3=float(value[4])
test3.append(score3)
averagescore=calcaverage(test1,test2,test3)
infile.close()
print(line)
_______________________________________________
Tutor maillist - [email protected]
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor