Four Corners

Python for AIEasy+10 XP+10

Four Corners

A grid of numbers is stored as a list of rows, and each row is a list.

Write corner_sum(grid) that returns the sum of the four corner numbers: top-left, top-right, bottom-left and bottom-right.

  • The grid always has at least 2 rows and 2 columns.
  • Every row has the same length.

Examples

grid = [[1, 2], [3, 4]]
returns 10
grid = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
returns 20
grid = [[5, 0, 0, 5], [1, 1, 1, 1]]
returns 12

Hints

Solve it to unlock the solution

Once your code passes every test, a reference solution shows up here so you can compare it with yours.

solution.py
CtrlEnterto run