Try it on paper first. A hint, the key idea and the worked solution are here when you need them.
Write a function total(items) that adds a list, and a function average(items) that uses total. What are they for ?
A function can call another function. Build big jobs from small functions.
Have you tried it?
Work it out on paper first. It is fine to get stuck or make a mistake: that is how we learn. When you are ready, compare your working with the solution.
Plan. total goes through the list with a loop. average calls total and divides by len(items).
total(marks) is .average(marks) is .Because average uses total, there is only one place where the adding is done.
Log in to join the discussion.
Loading…