This program will be ran through a Python 3 IDE. The function avgavg() takes as
ID: 3680424 • Letter: T
Question
This program will be ran through a Python 3 IDE.
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:
[[95, 92, 86], [66, 75, 54], [89, 72, 100], [34, 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.
Here is an example of how the function should work:
>>> avgavg([[95, 92, 86], [66, 75, 54], [89, 72, 100], [34, 0, 0]])
[91.0, 65.0, 87.0, 11.333333333333334]
63.5833333333
Explanation / Answer
For better readable code see here : http://pastebin.com/KsN2cJSa
def avgavg(lst):
studentAvg = []
for row in lst:
studentTotal=0
for item in row:
studentTotal=studentTotal+item #summing marks of a student
studentTotal=studentTotal/3 #Find student average
studentAvg.append(studentTotal) #add this avg to list of averages
print(studentAvg)
avgTotal=0
for item in studentAvg:
avgTotal=avgTotal+item #now add each avg to get overall average.
avgTotal=avgTotal/len(studentAvg) #divide by number of student
print (avgTotal) #dispaly overall average
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.