We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 441320a commit 174ad08Copy full SHA for 174ad08
pascal_triangle.py
@@ -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