118k views
0 votes
2) Write a function called upsidedown_pyramid(height) that acceptsa parameter ""height"". It then prints an upside-down pyramid of that height.(30

1 Answer

1 vote

Hello, you haven't provided the programing language in which you need the code, I'll explain how to do it using Python, and you can follow the same logic to make a program in the programing language that you need.

Answer:

# -*- coding: utf-8 -*-

#Python

def upsidedown_pyramid(height):

maximun = (2*(height-1))+1

for i in range(height): print(' '*i+'*'*(maximun-i*2)+' '*i)

Step-by-step explanation:

  1. Define your function with an input parameter
  2. Define your maximum, because you are not printing a normal pyramid but an upside-down pyramid you are going to start printing from the maximum number of '*' to just one, but what exactly is the maximum number of '*'? Because you build a pyramid starting with one block, '*', and each level you add two more blocks your formula to calculate the maximum is (2*(height-1))+1
  3. Finally, you have to create a for loop to print each level. You need to start printing zero spaces and the maximum number of blocks, the next level you need two spaces and the maximum number of blocks minus two, and for each level that follows you are increasing by two the number of spaces, one left and one right, and decreasing by two the number of '*'

Note the constructing block of this pyramid is *

2) Write a function called upsidedown_pyramid(height) that acceptsa parameter &quot-example-1
User Glrs
by
3.2k points