Home ยป Pyramid Star Pattern in python

Pyramid Star Pattern in python

Java SE 11 Developer (Upgrade) [1Z0-817]
1 Year Subscription
Java SE 11 Programmer II [1Z0-816] Practice Tests
Java SE 11 Programmer I [1Z0-815] Practice Tests
Oracle Java Certification
Spring Framework Basics Video Course

In this example we print a pyramid star pattern in python

Table of Contents

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