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
I'm trying to write 4 Functions to extract data from files into Student name, Score1, Score2 and Score 3 lists. then from there I'm trying to create a function that will calculate the average test score using the score1, score2, score3. After that I'm trying to create a function that will to write to file using Student name, lettergrade list. Here is my program so far. def calcaverage(test1,test2,test3): for count in range(test1,test2,test3): curraverage=0 curraverage=((test1[count]+ test2[count]+ test3[count])/3) currentaverage.append(curraverage) if curraverage>= 90: grade= "A" lettergrades.append(grade) elif curraverage >= 80 and curraverage < 90: grade= "B" lettergrades.append(grade) elif curraverage >= 70 and curraverage < 80: grade= "C" lettergrades.append(grade) elif curraverage < 70: grade= "F" lettergrades.append(grade) name=[] test1=[] test2=[] test3=[] averagescore=[] lettergrades=[] with open ("period1.txt", 'r') as infile: for line in infile: values = line.split() name.append(values[0] + ','+ values[1]) for line in infile: values = line.split() score1=float(values[2]) test1.append(score1) for line in infile: values = line.split() score2=float(values[3]) test2.append(score2) for line in inline: values = line.split() score3=float(values[4]) test3.append(score3) averagescore=calcaverage(test1,test2,test3) print(line)
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor