# Title: Pascal's triangle
# Heading: Python Program to Print Pascal's Triangle
# Level: beginner
# Tags: pascal's triangle, number pattern, binomial coefficients, lists
# About: Prints Pascal's triangle, working out each row from the one above it: every number inside a row is the sum of the two above it.

def pascals_triangle(n):
    """Print the first n rows of Pascal's triangle."""
    row = [1]
    for i in range(n):
        # 4 characters per number; each row starts 2 further left
        line = " " * 2 * (n - 1 - i)
        for number in row:
            line += f"{number:4}"
        print(line)

        # The next row: 1, each pair of neighbours added, then 1
        next_row = [1]
        for k in range(1, len(row)):
            next_row.append(row[k - 1] + row[k])
        next_row.append(1)
        row = next_row


pascals_triangle(6)
