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

python idle 3.6 grades1.txt Domel a12001 a 90 92 89 99 98 92 10 Fischer a12111 8

ID: 3836104 • Letter: P

Question

python idle 3.6

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

3. writ a program, student Avg(ifile), which will calculate the average score for each e student. Each file contains a name followed by an id followed by a series of eight grades. This program will calculate the average score for each student. Include in the code, except code to catch non-numeric grades. Non will be by-passed in the average calculation. The code will also use try/except to catch the file not found error. In addition, the code will use a try/except to check for an empty file. The code for this check is in the template. Place it in the appropriate try/except position. studentAvg empty file.txt') File is empty studentAvg ('nosuchfile. txt') File not found p>> student Avg grade s2.txt Error Non-numeric Name Domel Number of assignments 7 Average score 0.0', Name Fischer Number of assignments: 8 Average score: 90.0 studentavg ('grade sl txt') ['Error Non-numeric Name: Domel Number of assignments 7 Average score 81.428 57142 857143 Name Fischer Number of assignments: 8 Average score 74.125 'N ame: Hope Number of assignments 8 Average score 100.0 Name Patel Number of assignments 8 Average score 90.375']

Explanation / Answer

def studentAvg(fname):
try:
f = open(fname, 'r')
tmp_vals = []
correct_rcrs = []
for val in f:
tmp_vals.append(val.strip(' '))
if len(tmp_vals) == 0:
print("File is Empty")
else:
for val in tmp_vals:
tmp_val = val.split(' ')
correct_rcrs.append(tmp_val)

for i in range(len(correct_rcrs)):
temp_val = correct_rcrs[i][2:]

temp_val = list(filter(None, temp_val))

sum_of_vals = 0
no_of_records =0
for k in temp_val:

if k.isdigit():
no_of_records += 1

sum_of_vals += int(k)
else:
pass

print("Name: ", correct_rcrs[i][0], "No.of records: ", str(no_of_records), "Average: ", str(sum_of_vals/no_of_records))
  
  
  
except:
print("File Not Found")