The listing below prints a nicely-formatted depiction of Pascal's Triangle.

```
# Output the first nmax rows of Pascal's Triangle
nmax = 8
rows = [[1],[1,1]]
for n in range(2, nmax+1):
rows.append([1,])
# Insert the entries for this row by summing neighbours in the previous row
for k in range(n-1):
rows[n].append(rows[n-1][k]+rows[n-1][k+1])
rows[n].append(1)
# Pretty-print the rows as centered strings of numbers
for i,row in enumerate(rows):
print('{row:^{length:d}}'.format(length=4*(nmax+1),
row=('{:4d}'*(i+1)).format(*row)))
```

The numbers in each row are calculated by summing the neighbouring numbers from the row above (with additional 1s at the start and end of each row). The nice formatting is acheived by first creating a string representation of the numbers in a row in 4-character fields, and then centring this string in a width equal to the maximum width taken up by the final row.

```
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
1 6 15 20 15 6 1
1 7 21 35 35 21 7 1
1 8 28 56 70 56 28 8 1
```