python 3.6 idle grades1.txt Domel a12001 a 90 92 89 99 98 92 10 Fischer a12111 8
ID: 3835927 • Letter: P
Question
python 3.6 idle
grades1.txt
Domel a12001 a 90 92 89 99 98 92 10
Fischer a12111 89 99 17 100 18 88 91 91
Hope b12777 100 100 100 100 100 100 100 100
Patel a12010 100 78 88 99 100 78 90 90
grades2.txt
Domel a12001 m 0 0 0 0 0 0 0
Fischer a12111 90 90 90 90 90 90 90 90
Explanation / Answer
Code to read the data from the text file and print the number of students and average scores.
file=open("grades1.txt","r")
line = file.readline()
students=[]
count=0# count for the number of students
while line != "":
splitedline=line.split(" ")#to read the scores of the students
average=0
for i in range(len(splitedline)-1) : #loop for each students
average+=int (splitedline[i+1])
average=average/(len(splitedline)-1)
line = file.readline()
count=count+1
print("Total number of students:",count," Average score:",average)
file.close()
Ouptut:
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.