10 Triangular Pattern Programs in Python
1. Right-Angled Triangle of Stars
for i in range(1, 6):
print("*" * i)
2. Inverted Right-Angled Triangle of Stars
for i in range(5, 0, -1):
print("*" * i)
3. Right-Aligned Triangle of Stars
for i in range(1, 6):
print(" " * (5 - i) + "*" * i)
4. Inverted Right-Aligned Triangle of Stars
for i in range(5, 0, -1):
print(" " * (5 - i) + "*" * i)
5. Pyramid Pattern of Stars
for i in range(1, 6):
print(" " * (5 - i) + "*" * (2 * i - 1))
6. Inverted Pyramid Pattern
for i in range(5, 0, -1):
print(" " * (5 - i) + "*" * (2 * i - 1))
7. Triangle of Numbers
for i in range(1, 6):
for j in range(1, i + 1):
print(j, end="")
print()
8. Triangle of Alphabets
for i in range(1, 6):
for j in range(65, 65 + i):
print(chr(j), end="")
print()
9. Floyd's Triangle
num = 1
for i in range(1, 6):
for j in range(i):
print(num, end=" ")
num += 1
print()
10. Pascal's Triangle
def factorial(n):
return 1 if n == 0 else n * factorial(n - 1)
for i in range(5):
print(" " * (5 - i), end="")
for j in range(i + 1):
val = factorial(i) // (factorial(j) * factorial(i - j))
print(val, end=" ")
print()