# Pascal triangle in Python

Hello, I have problem with my code. I am programming the python triangle and numbers are printing fine but I don’t know how to put them into this pyramid scheme:

Can someone help me fix this problem?

My code:

``````from math import comb
def pascalov_trojuholnik(tab):
tab = []

for i in range(pocet):
for j in range(i+1):
cislo = comb(i, j)

return tab

tab = pascalov_trojuholnik(tab)
``````
``````from math import comb

def pascalov_trojuholnik(pocet):
tab = []

for i in range(pocet):
for j in range(i+1):
cislo = comb(i, j)

for row in tab:
print(" "*(pocet-len(row)), end=" ")
for num in row:
print(num, end=" ")
print()

pocet = int(input('Enter the number of rows: '))
pascalov_trojuholnik(pocet)
``````

define a function `pascalov_trojuholnik` that takes the number of rows as input and then prints the Pascal’s triangle in a pyramid shape.

Do you have some advice that could help them solve this on their own, instead of writing the code for them?

I’ve blurred the solution for now, to be used only in case of emergency.

Thanks!

2 Likes

thank you so much

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.