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
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")
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.