I am new to Python. Can somebody explain please why is this code not populating the 2D array as Pascal's triangle?
def PascalTri(n):
ar=[[0]*n]*n
print(ar)
for i in range(0,n):
for j in range(0,i+1):
if j==0 or i==j:
ar[i][j]=1
else:
ar[i][j]=ar[i-1][j-1] + ar[i-1][j]
print(ar)
PascalTri(5)
Output :
[[0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]]
[[1, 4, 8, 9, 1], [1, 4, 8, 9, 1], [1, 4, 8, 9, 1], [1, 4, 8, 9, 1], [1, 4, 8, 9, 1]]