Grid total
Inputs
cells is a grid: a list of 1 to 5 rows, each with the same number (1 to 5) of whole numbers from -9 to 9.
Your tasks
- Create a number
totalthat starts at 0. - Use an outer loop over the rows of
cellsand an inner loop over the numbers in each row. Add every number tototal. - Complete
gridSumso it returnstotal. Return it, do not print it.
Example
With cells = [[1, 2, 3], [4, 5, 6]], gridSum returns 21.
Rules
- Every row is the same length.
Test data
TEST DATA 1: cells is [[1, 2, 3], [4, 5, 6]]
TEST DATA 2: cells is [[0]]
Practice focus
Two-dimensional data is a loop over rows with a loop over columns inside. Grids lead straight to flood fill, islands, dynamic programming tables and path problems.