What is wrong in the method end
in the code?
The method end
returns always 1 although it should return 0 with the current data.
# return 1 if the sum of four consecutive elements equal the sum over other sum of the other three sums
# else return 0
# Eg the current sums "35 34 34 34" should return 0
data = "2|15|14|4|12|6|7|9|8|10|11|5|13|3|2|16"
arra = data.split("|");
def do_row ( arra, n ):
return arra[4*n:4 + 4*n]
def row_summa (row):
return sum(map(int,row))
def end ( summat ): # problem here!
equality = 1
for i in summat[2:5]:
print "Comparing: ", summat[1], " and ", i, ".\n"
if summat[1] != i:
equality = 0
print equality
for i in range(0,4):
summat = []
summat.append( row_summa( do_row(arra,i) ) )
print row_summa ( do_row(arra,i) )
summa = 0
end(summat)