Code for Number with Star Pyramid Pattern in Python

Hello Coders, In this blog post, you will learn to Write the code of a Number with the Star Pyramid pattern in Python. This is one of the trickiest questions requested most in the past few days. So here’s the code for it:-

Number with star pyramid pattern

Write a Python Code to print this Ouput:-

Output 1:-

for value n = 6

3*3*3
2*2
1
1
2*2
3*3*3

Code for This is:-

r = int(input(“a: “))
a = int(r/2)
for i in range(a,0,-1):
    n=i
    for j in range(0,i):
        b = i-1
        if (j==b):
            print(n,end=)
        else:
            print(n,end=“*”)
    print(“\r”)
for i in range (1,a+1):
    n = i
    for j in range(0,i):
        c = i-1
        if(j==c):
            print(n,end=)
        else:
            print(n,end=“*”)
    print(“\r”)

Write a Python Program to get this number with star pyramid Pattern Output:-

Output 2:-

for value n = 8

4*4*4*4*
3*3*3*
2*2*
1*
1*
2*2*
3*3*3*
4*4*4*4*

Code for This is:-

r = int(input(“a: “))
a = int(r/2)
for i in range(a,0,-1):
    n=i
    for j in range(0,i):
        b = i-1
        print(n,end=“*”)
    print(“\r”)
for i in range (1,a+1):
    n = i
    for j in range(0,i):
        c = i-1
        print(n,end=“*”)
    print(“\r”)

Hope this blog post was helpful to you and you have got the answer to your question. Thank you for visiting our blog. If you have any doubts about any coding questions then let us know in the comments section we will answer them as soon as possible. Till then check out our more blog posts.

Leave a Comment

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