x = [0] * 10
for i in range(len(x)):
x[i] = [0] * (i + 1)
for j in range(len(x[i])):
x[i][0] = x[i][-1] = 1
for i in range(2,len(x)):
for j in range(1, len(x[i])):
if j < len(x[i]) - 1:
x[i][j] = x[i-1][j-1] + x[i-1][j]
else:
break
s = 0
y = [0] * 10
for i in range(len(y)):
y[i] = [' '] * 20
for j in range(len(y[i])):
if i >= j:
y[i][10-i+s] = x[i][j]
s += 2
else:
s = 0
break
print(y[i][j], end=' ')
print()
Printing Results:
1
1 6
1 7 21
1 8 28 56
1 9 36 84 126
To make it easier to see, change the character space to 0, as shown below:
0
0 0
0 0 0
0 0 0 0
0 0 0 0 0
0 0 0 0 0 1
0 0 0 0 1 0 6
0 0 0 1 0 7 0 21
0 0 1 0 8 0 28 0 56
0 1 0 9 0 36 0 84 0 126
Why does it start printing from row 5 and column 5?
New contributor
Losdrift is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.