def sierpinski_triangle(n):
if n == 1:
return " /\\", "/--\\"
prev_triangle = sierpinski_triangle(n - 1)
size = len(prev_triangle)
new_triangle = []
# Add the top part of the triangle
for row in prev_triangle:
new_triangle.append(" " * size + row + " " * size)
# Add the bottom part of the triangle
for row in prev_triangle:
new_triangle.append(row + " " + row)
return new_triangle
def print_sierpinski_triangle(n):
triangle = sierpinski_triangle(n)
for row in triangle:
print(row)
# Test cases
print("Test case 1: 3")
print_sierpinski_triangle(3)
print("\nTest case 2: 2")
print_sierpinski_triangle(2)
print("\nTest case 3: 1")
print_sierpinski_triangle(1)