Diagnose a delivery-time traversal

A programmer wants to total all four delivery times, measured in seconds, but runs the Python code below. An IndexError stops execution when the code tries to access an invalid sequence index. The failed addition does not change total.


Python
times = [5, 8, 6, 9]
total = 0
for i in range(1, len(times) + 1):
    total = total + times[i]


Find the total immediately before the error, the number of successful additions, the first invalid index attempted, and the intended total of all four times. Give both totals in seconds to zero decimal places, and give the other answers as exact integers.

Your answers

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

More enumerate Questions: