Created
December 7, 2024 14:48
-
-
Save ghamarian/2fa61565ceb8a67b20fdbf7fcff39e7e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def next_row(a): | |
return [0] + [a + b for a, b in zip(a, a[1:])] + [0] | |
def g(n): | |
lst = [[0, 1, 0]] | |
for _ in range(n): | |
lst.append(next_row(lst[-1])) | |
return lst | |
def print_pascal(pascal_lists): | |
longest_size = len(pascal_lists[-1]) | |
for lst in pascal_lists: | |
current_length = len(lst) | |
content = " ".join([f"{item:^5}" for item in lst if item != 0]) | |
print(f'{" " * ((longest_size - current_length)) *3 }{content}') | |
print_pascal(g(14)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment