Thursday, 23 December 2021

Repeating triangle pattern in Python

I need to make a triangle of triangle pattern of * depending on the integer input.

For example:

n = 2

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

n = 3

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

I've already figured out the code for a single triangle, but I don't know how to duplicate them so they'll appear like a triangle of triangles.

Here's my code for one triangle:

rows = int(input())

for i in range(rows):
    for j in range(i, rows):
        print(" ", end="")
    for j in range(i):
        print("*", end="")
    for j in range(i + 1):
        print("*", end="")
    print()


from Repeating triangle pattern in Python

No comments:

Post a Comment