Home ยป Pyramid Star Pattern in python

Pyramid Star Pattern in python

In this example we print a pyramid star pattern in python

Code

rows = int(input("Enter amount of rows = "))

print("Pattern") 

for i in range(0, rows):
    for j in range(0, rows - i - 1):
        print(end = ' ')
    for k in range(0, i + 1):
        print('*', end = ' ')
    print()

When you run this you will something like this

alternative example

def drawPyramid(rows, symbol):
    for i in range(0, rows):
        for j in range(0, rows - i - 1):
            print(end = ' ')
        for k in range(0, i + 1):
            print('%c' %symbol, end = ' ')
        print()


rows = int(input("Enter amount of rows = "))
symbol = input("Symbol  = ")


drawPyramid(rows, symbol)

 

You may also like

Leave a Comment

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More