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:
images
Can someone help me fix this problem?

My code:

from math import comb
def pascalov_trojuholnik(tab):
    pocet = int(input('zadaj pocet: '))
    tab = []

    for i in range(pocet):
        riadok = []
        for j in range(i+1):
            cislo = comb(i, j)
            riadok.append(cislo)
        tab.append(riadok)
    
    return tab

tab = pascalov_trojuholnik(tab)
from math import comb

def pascalov_trojuholnik(pocet):
    tab = []

    for i in range(pocet):
        riadok = []
        for j in range(i+1):
            cislo = comb(i, j)
            riadok.append(cislo)
        tab.append(riadok)

    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? :pray:

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

Thanks!

2 Likes

thank you so much :slight_smile:

1 Like