In: Computer Science
#python #code #AP class #Tech
write a function code script which will print out number pyramid in the form of * so the output will be made up of **** resting on top of each other to form a pyramid shape. Bottom layer should be made of 5 multiplication signs like ***** then next 4 multiplication signs and so on. Top part should have only one *
Ans:-
Code:-
#Pyramid Function to draw the Pyramid pattern
def Pyramid(n):
#Outer loop it will run for n times to handle all the rows
for i in range(0,n):
#inner loop it will run for than i+1 times in order to print * pattern
#it will handle all the column basically
for j in range(0,i+1):
print("*",end="") #it will print * pattern
print() #it will print new line at the end of each row
Pyramid(5) #call to the Function to draw pattern
Output:-
Screeshot:-