def print_pascals_triangle(n):
triangle = [[1]]
for i in range(1, n):
previous_row = triangle[-1]
current_row = [1]
for j in range(1, len(previous_row)):
current_row.append(previous_row[j - 1] + previous_row[j])
current_row.append(1)
triangle.append(current_row)
for row in triangle:
print(" " * (n - len(row)), " ".join(map(str, row)))
rows = int(input("Enter the number of rows: "))
print_pascals_triangle(rows)
#source code --> clcoding.com
0 Comments:
Post a Comment