Search for question
Question

Question 3: (file name: largest sum.py) (35 points): Given a string of digits, calculate the largest sum for a contiguous substring of digits of length n. For example, for the input '027839564', the largest sum for a series of 3 contiguous digits is 20 (8 +3 + 9), and the largest sum for a series of 5 digits is 32 (7 + 8 +3+9+5). Note that the series are only required to occupy adjacent positions in the input; the digits need not be numerically consecutive. Define a function called largest_sum that accept two parameters, one string parameter with only digits, and another integer parameter that identifies the length of the series. This function should return the largest sum for a contiguous substring of digits in the given input. For example, the following function call should return 36. largest sum('73167176531330624919225119674426574742355349194934', 6) Demonstrate its use by printing the result of the example above.

Fig: 1