nzec error in python.

This is the code for the trianglesum problem. I’m getting an nzec error. I though it is due to some extra spaces problem. But even after using split() it doesn’t work. I’ve checked the forum but couldn’t find an answer to my problem. Any kind of help will be deeply appreciated.

t = raw_input().split()
for i in range(int(t[0])):
    n = []
    tx = raw_input().split()
    for k in range(int(tx[0])):
    summ = int(n[0])
    x = 0
    for l in range(1, int(tx[0])) :
	    if int(n[l][x]) > int(n[l][x+1]):
		    summ = summ + int(n[l][x])
		    summ = summ + int(n[l][x+1])
		    x = x+1
    print summ

your code runs out of string length. see here .
Make sure your for loop limits are correct.

not very sure but i think it is same as StringIndexOutOfBounds exceotion in java.

yes i think that itself is the problem in your if condition you have checked for

 if int(n[l][x]) > int(n[l][x+1]): 

here you must check if (x+1) is lesser than string length otherwise it runs out of the index!

hope that helps.


problem link:

thnx!:slight_smile: that was helpful!

1 Like