Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a Python function Pyramid() which takes a positive int value as the formal

ID: 3778720 • Letter: W

Question

Write a Python function Pyramid() which takes a positive int value as the formal parameter and returns no value. The value determines the number of rows of the pyramid. A pyramid has one star at the top and the number of stars increments by two on each subsequent row. (See the sample output in the starter code.) Use the starter code bellow to begin, def Pyramid(n): # Your code goes here def test__pyramid(): for i in range(5, 12, 3): Pyramid(i) print () test_pyramid() For this problem, you can use cither for loops or while loops. Do not modify the tes_rt() function. Spaces and stars must be printed one at a time.

Explanation / Answer

Please find the required program along with its output. Please see the comments against each line to understand the step.

def Pyramid(n):
for i in range(1,n): #outer loop for printing n no:of rows
for j in range(1,i): #inner loop for printing the *'s in a row
if(j==1): #print only one star in the top row
print("*",end='')
else: #add 2 stars for the rest of the rows
print("**",end='')
print() #for new line
  
  
def test_pyramid():
for i in range(5,12,3):
Pyramid(i)
print()
  

test_pyramid()

-------------------------------------------------------------------------

OUTPUT:

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote