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)