max python

Just another WordPress site

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)

 

Leave a Comment

Your email address will not be published. Required fields are marked *

This div height required for enabling the sticky sidebar
Ad Clicks : Ad Views : Ad Clicks : Ad Views :