PY
py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
def get_triangle(n):
out = [[1], [1, 1],[]]
stri = ''
max_dist = 2
for i in range(2, n-1):
out[i].append(1)
for j in range(1, i):
out[i].append(out[i][j-1] + out[i-1][j-1] + out[i-1][j])
out[i].append(1)
out.append([])
for i in range(n):
out[n-1].append(1)
for j in range(i+1):
if (i < n and j<n-1):
max_dist = len(str(out[-2][j]))
if j> n-3:
max_dist = len(str(out[-2][-3]))//2+1
dist = len(str(out[i][j]))//2
if j>=1:
dist += len(str(out[i][j-1]))//3
else:
dist = max_dist
stri += (' '*(max_dist-dist)) + str(out[i][j])
stri += '\n'
return stri
print(get_triangle(int(input())))
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run