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:
*
***
19
*****
*******
*********
*************
****************
*******************
# 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.
Already registered? Login
Not Account? Sign up
Enter your email address to reset your password
Back to Login? Click here