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

PYTHON: 5.45 The function avgavg() takes as input a list whose items are lists o

ID: 3678337 • Letter: P

Question

PYTHON:

5.45 The function avgavg() takes as input a list whose items are lists of three numbers. Each three-number list represents the three grades a particular student received for a course. For example, here is an input list for a class of four students: CC95,92,86], [66,75,54], [89, 72,100] C34,0,0]] The function avgavg() should print, on the screen. two lines. The first line will contain a list containing every student's average grade. The second line will contain just one number: the average class grade, defined as the average of all student average grades. avgavg(CC95, 92, 86], [66, 75, 54], [89, 72, 100), C34, 0, 0]]) [91.0, 65.0 87.0, 11.3333 333 33 333 334] 63.5833333333

Explanation / Answer

lists = eval(raw_input('Please enter the class data as a list: '))
def avgavg(lists):
avg = [float(sum(sub))/float(len(sub)) for sub in lists]
everything = [item for sub in lists for item in sub]
allavg = float(sum(everything))/float(len(everything))
return avg, allavg
avg, allavg = avgavg(lists)
print avg
print allavg