Table of Contents
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
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
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
Suggested post you
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
Multiply two numbers in Java using scanner| 5 different ways In this article, we will…
5 Different ways to Divide two numbers in Java using scanner In this article, we…
Learn 8 Ways to Subtract Two Numbers Using Methods in Java In this article, we…
10 ways to subtract two numbers in Java In this article, we will discuss the…
Java Code Examples – Multiply Two Numbers in 5 Easy Ways In this article, we…
How to Divide two numbers in Java| 5 different ways In this article, we will…
This website uses cookies.