xxxxxxxxxx
def printPascal(n):
for i in range(1,n + 1):
m = 1;
for j in range(1,i + 1):
print(m, end = " ")
m = int(m * (i - j) / j)
print("")
printPascal(int(input()))
#code by fawlid
xxxxxxxxxx
def solve(A):
pascals_triangle = []
for i in range(A):
pascals_triangle.append([1]*(i+1))
for i in range(2,A):
for j in range(1,i):
pascals_triangle[i][j] = pascals_triangle[i-1][j-1] + pascals_triangle[i-1][j]
return pascals_triangle
xxxxxxxxxx
def generate_pascal_triangle(rows):
triangle = []
for i in range(rows):
row = [1] * (i+1)
if i > 1:
prev_row = triangle[i-1]
for j in range(1, i):
row[j] = prev_row[j-1] + prev_row[j]
triangle.append(row)
return triangle
def print_pascal_triangle(triangle):
for row in triangle:
print(" ".join(str(num) for num in row))
# Generate and print Pascal's Triangle with 10 rows
rows = 10
pascal_triangle = generate_pascal_triangle(rows)
print_pascal_triangle(pascal_triangle)