Python Program - Create Pyramid Patterns
https://www.theitroad.com
Here is an example Python program that creates various pyramid patterns using nested loops:
# Pyramid pattern with user input n = int(input("Enter the number of rows: ")) for i in range(n): print(" "*(n-i-1) + "*"*(2*i+1)) # Inverted pyramid pattern with user input n = int(input("Enter the number of rows: ")) for i in range(n): print(" "*i + "*"*(2*(n-i)-1)) # Half pyramid pattern with user input n = int(input("Enter the number of rows: ")) for i in range(1, n+1): print("*"*i) # Half pyramid pattern with numbers with user input n = int(input("Enter the number of rows: ")) for i in range(1, n+1): for j in range(1, i+1): print(j, end="") print() # Floyd's triangle with user input n = int(input("Enter the number of rows: ")) num = 1 for i in range(n): for j in range(i+1): print(num, end=" ") num += 1 print()
The first pattern is a regular pyramid pattern, the second is an inverted pyramid pattern, the third is a half pyramid pattern, the fourth is a half pyramid pattern with numbers, and the last one is Floyd's triangle.