Drop links or images here to add them to the editor.

Another make task, and this time the inner loop works something out for every row.

A teacher keeps the test scores of three students in three subjects. They are stored in a 2D array where the first item on each row is the student’s name, followed by their three test scores.

results = [["Ali", 45, 60, 55], ["Bea", 70, 80, 75], ["Cam", 30, 40, 35]]

Your task

Start your program with the results line exactly as it is above. Then write code that:

The output

Three lines, one per student, in the order they are in the array. NAME is the student’s name and AVERAGE their average score:

NAME has an average score of AVERAGE

Example

Output:

Ali has an average score of 53
Bea has an average score of 75
Cam has an average score of 35

Ali’s scores add up to 160, and 160 divided by 3 is 53 and a third. Integer division drops the part after the decimal point, so the average is 53.

The tests also check your code: a program that does not have a for loop inside a for loop, or that does not use //, does not pass.

Help! My code doesn't work!

Make sure that you check for the following things:

  • The name is in column 0 and the scores are in columns 1, 2 and 3, so the inner loop’s range starts at 1.
  • The total is set to 0 inside the outer loop, before the inner loop, so that every student starts again from 0.
  • The average is worked out and printed after the inner loop has finished, but still inside the outer loop.
  • The average uses //, not /. With / you get 53.333333333333336 and 75.0.
  • The average is wrapped in str() before it is joined onto the text with a +.