lundi 21 octobre 2019

Why is this function returning all True values?

I am defining a function that takes the sum of each list and checks to see whether the individual sum of each list is even. If it is even, I would like to return True. Otherwise, I would like to return False

def evenrow(intList):

for i in intList:
    if sum(i)%2==1:
        return False
    else:
        return True


print((evenrow([[1,3], [2,4],[0,6]]))) 

print((evenrow([[1,3,2], [3,4,7], [0,6,2]])))

print((evenrow([[1,3,2], [3,4,7], [0,5,2]])))

I want it to iterate through the sum of each list, but it looks like right now the loop is just checking the first list and stopping.

Also, is there any way to display the answer by not including the print statement? I feel like I have done that in the past, but it does not seem to be working for me this time around.

Aucun commentaire:

Enregistrer un commentaire