SPLIT PYRAMID PATTERN IN PYTHON
AMRUHA AHMED
11th October,2023.
This article will aid you in the creation of a split pyramid pattern in Python using a combination of nested loops.
DELVING DEEPER:
- 1.This pattern requires the usage of nested loops to print the asterisks in the appropriate manner
- 2.One separate variable is required to check the number of spaces printed on the screen before the asterisks are printed
BREAK-UP OF THE PATTERN:
- 1.A total of 7 rows need to be printed in the pattern.
- 2.On each side of the split, the asterisks keep increasing by 1 after each iteration.
- 3.The dashes are an indication of spaces required. Before the outer loop begins, the space variable is initialized to 7 i.e the number of rows of asterisks to be printed on the screen.As observed from the above pattern, the spaces keep decreasing by 1 after each iteration.
- 4.The set of asterisks on the left side of the split are printed on the screen depending on the value of the outer loop counter.
- 5.A space is printed on the screen to impart the split look to the pyramid.
- 6.The number of asterisks to be printed on the right side of the split are determined by the value of the outer loop counter.
PROGRAM:
s=7 #for spaces
for i in range (1,8):
for j in range(1,s):
print(" ",end="")
for j in range(1,i):
print("* ",end="")
print(" ",end="")
for j in range(1,i):
print("* ",end="")
print("\n")
s=s-1;
OUTPUT: