Question: PYTHON Create a program that will output a pyramid of stars Functions are: construct_pyramid: This function will take the number of rows in the pyramid
PYTHON
Create a program that will output a pyramid of stars
Functions are:
construct_pyramid: This function will take the number of rows in the pyramid and construct the pyramid; returning it as a String. It is expected that this function will call construct_row for as many rows as needed. construct_row: This function takes the current row number and the maximum number of columns as input parameters and returns the constructed row as a String. While solving this lab, you will realize that additional variables need to be calculated to construct the pyramids properly. The maximum number of columns is one of those parameters The code # can be used for testing def main(): # call construct pyramid # print your pyramid print(construct_pyramid(5)) pass # construct the pyramid of stars def construct_pyramid(rows): output = '' # define max_columns using rows # loop for all rows # i = your row (current row) for i in range(rows): pass # call construct_row(i, max_columns) # output = output + construct_row # only add " " if current row is not the last row (how to define last row) return output # constructs a single row of stars # row_num = current row index # max_column = number of columns in table (total characters in row) def construct_row(row_num, max_columns): row = '' # example of string concatenation # row = row + " " # number_of_stars # number of total_spaces # half_spaces = total_spaces // 2 # construct spaces before the stars # after this loop we will have 2 spaces in our string (row) # " " for i in range(half_spaces): # concatenate a space to our string (row) pass # construct the stars in the row # after this loop we will three stars after the two spaces # " ***" # for i in range(2, 5) for i in range(number_of_stars): # concatenate a star to our string (row) pass # construct the spaces after the stars # " *** " for i in range(half_spaces): # concatenate a space to our string (row) pass return row if __name__ == '__main__': main()
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
