0

I am looking for help in how to implement function avg() that takes as input a list that contains lists of numbers. Each number list represents the grades a particular student received for a course. List for a class of four students.
([95,92,86,87],[66,54,],[89,72,100],[33,0,0]) the function avg should print one per line, every student's average grade.

Edited by pyTony: Corrected format

4
Contributors
3
Replies
33
Views
4 Years
Discussion Span
Last Post by BearofNH
1

Simply add the numbers in each list together with function sum() and divide by the number of items in the list.

0

grades = ([95,92,86,87],[66,54,],[89,72,100],[33,0,0])

    def avg(grades):
    for i in grades:
        avg = sum(i)/len(i)
        print("average = ",avg)

This should get you started.

0

Of course, NumPy (www.numpy.org) has exactly the routine you need.

Edited by BearofNH: [url] no workee

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.