Tuesday, 15 July 2014

python - attempting to add values of a 2D list to see if they equal to a even number -



python - attempting to add values of a 2D list to see if they equal to a even number -

i have concept problem trying work on.

the goal take 2d list. in each sub list of 2d list, sum values within. if sublists in 2d list equal numbers homecoming true, else homecoming false.

the code below have. errors far included below code.

input = evenrow([[1, 3], [2, 4], [0, 6]]) def evenrow (lst): row in lst: unit in row: if sum(int(unit)) %2 == 0: homecoming true homecoming false

errors =

traceback (most recent phone call last): file "<pyshell#0>", line 1, in <module> evenrow([[1, 3], [2, 4], [0, 6]]) file "c:\users\christopher\downloads\pratice.py", line 57, in evenrow if sum(int(unit)) %2 == 0: typeerror: 'int' object not iterable

try this:

def evenrow(lst): row in lst: if sum(row) % 2 != 0: # if sum of @ to the lowest degree 1 sublist not homecoming false # homecoming false. homecoming true # if line, sums even.

python list

No comments:

Post a Comment