Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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

Write a program calcAyg(ifile), which will calculate the average score for the first assessment on each line of the file. Each file contains a name followed by an id followed by a series of grades. This calculat e the average of the first grade program in the series. Include in the code, try/except code to catch non-numeric grades Non- numerics will be by-passed in the average calculation. The code will also use try/except to catch the file not found error. The program will return a string as shown below. calcAvg nosuchfile .txt 'File not found. calcAvg grades .txt Total number of students: 4 Average score: 97 calcAvg ('grades 1.txt') 'Non-numeric found. Total number of students: 3 Average score: 96 calcAvg ('grades .txt') 'Non-numeric found. Total number of students 1 Average score: 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: