I have successfully written the code that works and is less than 256 bytes. But when I'm taking the inputs for the values of elements in the n lines, I'm not able to take them in the same line. I have to press enter every time, producing an NZEC error. I would like to know how I could fix that.

t=int(raw_input())
while t:
   n=int(raw_input())
   a=[]
   for i in range(n):
    a.append([])
    for j in range(i+1):
     a[i].append(int(raw_input()))
   for i in range(n-1)[::-1]:
    for j in range(i+1):
     a[i][j]+=max(a[i+1][j],a[i+1][j+1])
   print a[0][0]
   t-=1
  • created

    Dec '14
  • last reply

    Dec '14
  • 1

    reply

  • 364

    views

  • 2

    users

Looks like you are new to python.

1.Indentation is must in Python. - Your code is not indented properly.

2.Python is NOT C/C++ you just can't neglect all the white spaces. (unless you choose to read all input at once)
So, reading 'n' numbers from a line and 'n' numbers from 'n' lines are two "different" things here.
Now, depending on how many numbers you want to read from a line, you can directly convert that to an int, or you can split it and then convert them to ints.