Use a for loop to determine the first output line by adding A[i-1] each time. Then use a nested for loop in a while loop to determine the remaining four output lines by adding if the index in the for loop is less than the index, else then subtract in the while loop.
Note: the print(*list) syntax removes the square brackets and commas in a list
#input
N = input().split()
#first output line
dist = [0]
sd = 0
for i in range(1, 5):
sd += int(N[i-1])
dist.append(sd)
print(*dist)
#last four ouput lines
j = 1
while j < 5:
current = dist[j]
for i in range(5):
if i < j:
dist[i] += current
else:
dist[i] -= current
print(*dist)
j += 1
Comments