python -Write a Python function Pyramid() which takes a positive int value as th
ID: 3778894 • Letter: P
Question
python -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. Starter code below. def Pyramid(n): Your code goes here def test pyramid0: for i in print0 test pyramid( 1-Use the starter code to begin with. 2-use either for loops or while loops. 3-Spaces and stars must be printed one at a time. 4-Do not modify the tes rt0 function. on each row of the triangle, you must draw a number of space(s) first, using a while loop, before star(s). To find an algorithm, you may want to analyze the relationship among the number of spaces, the number of stars, and the row number. The output should be like the output below.Explanation / Answer
Here is the required code for a python program to print the tree using '*'
Code:
def Pyramid(n):
for i in range(n):
print ' '*(n-i-1) + '*'*(2*i+1)
def test_pyramid():
for i in range(5,12,3):
Pyramid(i)
test_pyramid()
Explanation:
*The given block of code is being used as a reference
*The Method Pyramid is being implemented to print the required tree sequence
*In python ' '*2 will print you two spaces.
Eg: 'a'*3 will print aaa
'4'*4 will print 4444
hence we used this python feature in our code to simplify our code.
*No modification is being done on either of the function definations and function calls
*For loop is being used in the program to maintain consistency.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.