Editorial for Pascal's Triangle


Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.

Author: wadeyao

def pascal(row, col):
    if col == 0 or row == col:
        return 1
    return pascal(row-1, col-1) + pascal(row-1, col)

def print_pascal(n):
    for i in range(n):
        for j in range(i+1):
            print(f'{pascal(i, j):3d}', end='')
        print()

Comments

There are no comments at the moment.