Skip to content

Commit 174ad08

Browse files
committed
Added pascal_triangle.py
1 parent 441320a commit 174ad08

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

pascal_triangle.py

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from permutations_combinations import PermutationsCombinations
2+
3+
4+
class PascalTriangle:
5+
@staticmethod
6+
def pascal_triangle(rows: int) -> None:
7+
if not isinstance(rows, int):
8+
raise ArithmeticError("Number of rows in a Pascal's triangle cannot be non-integers.")
9+
elif rows < 0:
10+
raise ArithmeticError("Number of rows in a Pascal's triangle cannot be negative.")
11+
for n in range(rows):
12+
for r in range(rows - n + 1):
13+
print(end=" ")
14+
for r in range(n + 1):
15+
print(PermutationsCombinations.ncr(n, r), end=' ' if r != n else '')
16+
print()
17+
18+
19+
if __name__ == '__main__':
20+
PascalTriangle.pascal_triangle(int(input("Enter the number of rows: ")))

0 commit comments

Comments
 (0)