Pyramid Pattern – Python

inc = 1
n = 5
for x in range(1, n + 1):
    for y in range(n - 1,x - 1 ,-1):
        print(" ", end="") 
    for z in range(1, inc + 1): 
        if x == z:
           print(z, end="")
        else:
           print("*", end="")
    inc += 2; 
    print() 

inc = 1
n = 5
for x in range(1, n + 1):
    for y in range(n - 1,x - 1 ,-1): This is a loop
        print(" ", end="") 
inc = 1
n = 5
for x in range(1, n + 1):
    for y in range(n - 1,x - 1 ,-1):
        print(" ", end="") 
    for z in range(1, inc + 1): 
        if x == z:
           print(z, end="")
        else:
           print("*", end="")
    inc += 2; 
    print() 

Related Post

Leave a Reply

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


The reCAPTCHA verification period has expired. Please reload the page.