+ 1

# Wrong output

16th Dec 2019, 9:23 PM
Abdelhakim Dahaman + 4
def average_per_student(studentGrades): answer = [] for row in studentGrades: res = 0 loopCount = 0 for item in row: loopCount = loopCount + 1 res = res + item answer.append(res/loopCount) return answer def average_all_students(studentGrades): res = 0 loopCount = 0 for row in studentGrades: for item in row: res = res + item loopCount = loopCount + 1 return res/loopCount
16th Dec 2019, 10:12 PM
Diego + 2
Abdelhakim Dahaman I did not fully read the code yet, but it seems to me that you have so many variables that really have no use. 1. Make a function that calculates the average of ONE student only. 2. Use it in a second function, that calculates the average of all students.
16th Dec 2019, 9:33 PM
Aymane Boukrouh + 2
ok thanks, im gonna try that👍
16th Dec 2019, 9:39 PM
Abdelhakim Dahaman + 1
sometimes......it's better to scrap it all start again:- def average_per_student(grades): aps = [] for marks in grades: aps.append(round(sum(marks)/len(marks), 2)) return aps def average_all_students(grades): average = 0 for marks in grades: average += sum(marks)/len(marks) return round(average/len(grades), 2) studentGrades = [[95, 92, 86], [66, 75, 54], [89, 72, 100], [34, 0, 0]] print(*average_per_student(studentGrades), sep=', ') print(average_all_students(studentGrades)) also..have a look at the statistics module for "mean" (average).
16th Dec 2019, 11:07 PM
rodwynnejones 