-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday17_pascal_triangle.py
More file actions
30 lines (22 loc) · 857 Bytes
/
day17_pascal_triangle.py
File metadata and controls
30 lines (22 loc) · 857 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# ECX 30 DAYS OF CODE AND DESIGN
# Day 17
"""
**Pascal's triangle**
Task: \n
* Write a function that prints out the first "n" rows of Pascal's triangle.
Where "n" is an integer taken as argument of the function.
[See more](https://en.m.wikipedia.org/wiki/Pascal%27s_triangle)
"""
import math # For comb() [Combination] function
def pascal_triangle(numbers):
"""Prints Pascal's Triangle Using Combination"""
for num_of_elements in range(numbers + 1):
for selected_elements in range(num_of_elements + 1):
print(math.comb(num_of_elements, selected_elements), end=' ')
print('\n')
print(' Pascal\'s Triangle '.center(40, '*'))
try:
number = int(input('Enter the range of Pascal\'s triangle to print: '))
pascal_triangle(number)
except ValueError:
print('Invalid input. Enter an integer.')