From 4acb4f4cb1769ac01729f3bbe811aebc40cec2b0 Mon Sep 17 00:00:00 2001 From: aat Date: Sat, 31 May 2025 08:17:07 +0530 Subject: [PATCH] added pascal_triangle.py file --- .idea/.gitignore | 3 +++ .idea/Basic-Python-Programs.iml | 9 +++++++++ .idea/misc.xml | 6 ++++++ .idea/modules.xml | 8 ++++++++ .idea/vcs.xml | 6 ++++++ pascal_triangle.py | 15 +++++++++++++++ 6 files changed, 47 insertions(+) create mode 100644 .idea/.gitignore create mode 100644 .idea/Basic-Python-Programs.iml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml create mode 100644 pascal_triangle.py diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 00000000..26d33521 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/Basic-Python-Programs.iml b/.idea/Basic-Python-Programs.iml new file mode 100644 index 00000000..d6ebd480 --- /dev/null +++ b/.idea/Basic-Python-Programs.iml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 00000000..86331146 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 00000000..482f9449 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 00000000..35eb1ddf --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/pascal_triangle.py b/pascal_triangle.py new file mode 100644 index 00000000..d965050d --- /dev/null +++ b/pascal_triangle.py @@ -0,0 +1,15 @@ +def pascal_recursive(row, col): + if col == 0 or col == row: + return 1 + return pascal_recursive(row - 1, col - 1) + pascal_recursive(row - 1, col) + +def print_pascals_triangle(n): + for row in range(n): + print(' ' * (n - row), end='') # spacing for pyramid shape + for col in range(row + 1): + print(pascal_recursive(row, col), end=' ') + print() + + +rows = int(input("Enter number of rows: ")) +print_pascals_triangle(rows)