Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Introduction to nested lists
Iterating over nested lists
8. Calculating metrics for nested list rows
Modifying nested lists
Working with multiple lists
Summary

Instruction

Perfect! In the previous example, we calculated a single value for all the nested lists. Now let's see how we can calculate separate metrics for single "rows":

donations = [
  [345.0, 287.80, 119.27, 329.30],
  [294.25, 349.0, 178.90, 262.34],
  [401.0, 456.45, 289.43, 319.27]
]

for day in donations:
  daily_sum = 0
  for place in day:
    daily_sum += place
  print(daily_sum)

In the example above, we print the daily donation sums on separate lines. To that end, we create a temporary daily_sum variable inside the outer loop before we invoke the inner loop. Inside the inner loop, we add each source to the temporary variable. Then, back in the outer loop, we print the daily sum.

Exercise

For each of the four applications, find and print the average score given to the podium finishers:

Average score: {average value for app1}
Average score: {average value for app2}
Average score: {average value for app3}
Average score: {average value for app4}

Stuck? Here's a hint!

Create a temporary variable in the outer for loop. Add all three scores to the temporary variable and divide the sum by the number of elements to get the average for a given application.