54.6k views
0 votes
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

1 Answer

1 vote

From the question I understood, this is the code. Comment under the solution if there is something to be edited, but this should definitely work.

def draw_triangle(n):

if n == 1:

print('*'.center(19))

else:

draw_triangle(n-2)

print((n*'*').center(19))

draw_triangle(19)

User Pkazmierczak
by
4.4k points