Print a triangle pattern

Write a function named print_triangle_pattern that takes these inputs:

  • integer n: the height of the triangle;
  • string side: either "left" or "right".

The function must print a triangle pattern of n lines made of asterisks (*), aligned to the requested side. Use for loops.

Use a nonnegative height. Print 1 asterisk on the first line, 2 on the next, and continue through n. Right alignment uses leading spaces so every row ends in the same column. The function returns None.

Complete the supplied function in Listing 1. Keep its signature and use the checks below it.

Listing 1: Starter function and supplied checks for print a triangle pattern.
def print_triangle_pattern(n: int, side: str) -> None:
    # Add code here!
    pass


print_triangle_pattern(4, "left")

Listing 2 shows the expected printed result.

Listing 2: Expected output of the supplied example for print a triangle pattern.
*
**
***
****

Run the additional example in Listing 3.

Listing 3: Additional supplied example call for print a triangle pattern.
print_triangle_pattern(4, "right")

Listing 4 shows the expected printed result.

Listing 4: Expected output of the supplied example for print a triangle pattern.
   *
  **
 ***
****

range(start, stop) supplies integers beginning at start and ending before stop. For example, list(range(1, 4)) is [1, 2, 3]. An empty range supplies no values.

assert condition stops the check with an AssertionError when the condition is false. print(text) displays the supplied string followed by a newline; print("**") prints a row of 2 asterisks.

range(stop) supplies integers from 0 up to, but excluding, stop; list(range(3)) is [0, 1, 2].