Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Introduction
Built-in Functions Common to Most Data Structures
6. sum() – exercise
Summary

Instruction

Perfect! Before we move on, let's do an additional exercise with sum().

Exercise

Write a function named get_max_sum(input_list) that accepts a list of numbers, counts the sums of all three consecutive numbers in the list, and returns the greatest sum. E.g., consider the following input:

[13, 43, 83, 56, 67, 67, 39, 11, 43]

We can count the following sums of three consecutive numbers:

  • 13 + 43 + 83 = 139
  • 43 + 83 + 56 = 182
  • 83 + 56 + 67 = 206
  • 56 + 67 + 67 = 190
  • 67 + 67 + 39 = 173
  • 67 + 39 + 11 = 117
  • 39 + 11 + 43 = 93

So the function should return 206 (the greatest sum).

Stuck? Here's a hint!

Iterate over the indexes with:

for i in range(1, len(input_list)-2)

You can slice a list in the following way:

list[0:3]

The result will be a new list with the second and third element of the list.