Drop hier links of afbeeldingen om ze aan de editor toe te voegen.

Another modify task, and this time a loop picks out the items.

A fitness app stores a week’s step counts for three users in a 2D array. The first item on each row is the user’s name, followed by three daily step totals.

The program is supposed to add up the steps for the user on row 1, Mary, by looping through her step data, and then print her name with her total. The editor starts you off with this:

steps = [
    ["Bob", 5000, 6000, 5500],
    ["Mary", 8000, 9000, 8500],
    ["James", 4000, 3000, 4500]
]

total = 0

for i in range(1, 4):
    total = total + steps[1][1]

print(steps[0][0] + " walked " + str(total) + " steps")

Run it first. It prints Bob walked 24000 steps, which is wrong twice over: the steps are Mary’s, but the name is Bob’s, and the total is Mary’s first day added up three times.

Your task

Two indices are wrong. Change only those two.

The tests also check your code: a program without the for loop does not pass.

The output

One line:

Mary walked 25500 steps
Help! My code doesn't work!

Make sure that you check for the following things:

  • The loop counter i takes the values 1, 2 and 3. Those are exactly the columns that hold step counts.
  • The column index can be a variable. Use the loop counter there, not a number.
  • Mary is on row 1, because the rows count from zero.
  • The row index comes first and the column index second.