For ststement

Programs for printing full Pyramid star pattern in Python

Programs for printing full Pyramid star pattern in Python

In this article, we will discuss the Programs for printing full Pyramid star pattern in Python

In this post, we will learn how to create printing full Pyramid star pattern using for and while loop in Python language

pattern in Python

Full Pyramid pattern – using for loop

Program 1

The program displays the full pyramid star pattern using star symbol using for loop in Python language

# Python program to print full Pyramid pattern
rows=int(input("Enter the number of rows: "))
#Take input from user
print("print full Pyramid star pattern ")
k=0
for i in range (1,rows+1):
#outer for loop starts from i=1 to i= rows + 1
    for space in range(1,(rows-i)+1):
    #inner for loop print spaces using formula rows-i)+1
        print(end="  ")
        
    while k!=(2*i-1):
    #inner while loop print star using formula 2*i-1
        print("* ",end="")
        k+=1
    k=0
    print()

When the above code is executed, it produces the following result

 

 

Full Pyramid pattern (Inverted) – using for loop

Program 2

the program displays the inverted full  pyramid star pattern using the star symbol using for loop in Python language

 

# Python program to print inverted full Pyramid pattern
rows=int(input("Enter the number of rows:"))
#Ask input from user for rows
print("print full Pyramid star pattern")

for i in range (rows,1,-1):
    #outer for loop iterates from i=rows to i=1
    for space in range(0,(rows-i)):
        print("  ",end="")
        #first inner for loop print space 
    for j in range(i,(2*i-1)):
        print("* ",end="")
         #inner for loop print star to first half of Pyramid
    for j in range(1,i-1):
        print("* ",end="")
          #last inner for loop print star to othar half of Pyramid
    print()

When the above code is executed, it produces the following result

full Pyramid pattern

 

 

Suggested post you

For loop in Python language

While loop in Python language

Nested for loop in Python language

Nested while loop in Python language

If statements in Python language

Nested If statements in Python language

 

 

Similar post

C pyramid star pattern program – using loops

C++ pyramid star pattern program – using loops

Java pyramid star pattern program – using loops

C program to create an Inverted Pyramid star pattern

C++ program to create an Inverted Pyramid star pattern

Hollow Pyramid star pattern in C language

Hollow Pyramid star pattern in C++ language

Hollow reverse Pyramid pattern in C language

Hollow reverse Pyramid pattern in C+ language

 

Python full pyramid star pattern

Java full pyramid star pattern

Karmehavannan

Recent Posts

Multiply two numbers in Java using scanner| 5 different ways

Multiply two numbers in Java using scanner| 5 different ways In this article, we will…

3 months ago

5 different ways to Divide two numbers in Java using scanner

5 Different ways to Divide two numbers in Java using scanner In this article, we…

3 months ago

Learn 8 Ways to Subtract Two Numbers Using Methods in Java

Learn 8 Ways to Subtract Two Numbers Using Methods in Java In this article, we…

4 months ago

10 ways to subtract two numbers in Java

10 ways to subtract two numbers in Java In this article, we will discuss the…

4 months ago

Java Code Examples – Multiply Two Numbers in 5 Easy Ways

Java Code Examples – Multiply Two Numbers in 5 Easy Ways In this article, we…

4 months ago

How to Divide two numbers in Java| 5 different ways

How to Divide two numbers in Java| 5 different ways In this article, we will…

4 months ago

This website uses cookies.