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.

Recommended Answers

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

Jump to Post

All 3 Replies

Re: Help On Programming Python's 80 80

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

Re: Help On Programming Python's 80 80

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.

Re: Help On Programming Python's 80 80

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.