Write a recursive function called draw_triangle() that outputs lines of '*' to form a right side up isosceles triangle. Function draw_triangle() has one parameter, an integer representing the base...


Write a recursive function called draw_triangle() that outputs lines of '*' to form a right side up isosceles triangle. Function draw_triangle() has one parameter, an integer representing the base length of the triangle. Assume the base length is always odd and less than 20. Output 9 spaces before the first '*' on the first line for correct formatting.


Hint: The number of '*' increases by 2 for every line drawn.


Ex: If the input of the program is:


3


the function draw_triangle() outputs:


 *


***


Ex: If the input of the program is:


19


the function draw_triangle() outputs:


          *


         ***


       *****


     *******


    *********


  *************


 ****************


*******************



# TODO: Write recursive draw_triangle() function here.
def draw_triangle(base_length):
    char = '*'
    if base_length > 0:
        draw_triangle( base_length -2)
        print(char* base_length)





if __name__ == '__main__':
    base_length = int(input())
    draw_triangle(base_length)



Need some assistance getting the spacing right for the triangle, I can get it to print but it is all left aligned.



Jun 08, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here