How to sum a 2d array in Python?

python

Solution

This is the issue

for row in range (len(input)-1):
    for col in range(len(input[0])-1):

try

for row in range (len(input)):
    for col in range(len(input[0])):

Python's range(x) goes from 0..x-1 already

range(...) range([start,] stop[, step]) -> list of integers

Return a list containing an arithmetic progression of integers.
range(i, j) returns [i, i+1, i+2, ..., j-1]; start (!) defaults to 0.
When step is given, it specifies the increment (or decrement).
For example, range(4) returns [0, 1, 2, 3].  The end point is omitted!
These are exactly the valid indices for a list of 4 elements.

Problem

I want to sum a 2 dimensional array in python: Here is what I have: ``` def sum1(input): sum = 0 for row in range (len(input)-1): for col in range(len(input[0])-1): sum = sum + input[row][col] return sum print sum1([[1, 2],[3, 4],[5, 6]]) ``` It displays `4` instead of `21` (1+2+3+4+5+6 = 21). Where is my mistake?

Original source