Home » Pyramid Star Pattern in python

Pyramid Star Pattern in python

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

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