Python Pattern Programs - Printing Stars '*' in Right Angle Triangle Shape

Опубликовано: 10 Март 2026
на канале: Machine Learning Made Easy
37
4

In this article, I show you how to Print Pattern using for loop in Python. We will learn how to print asterisk (star), Diamond, half pyramid, inverted pyramid patterns using a loop, range() function.


1) First Simple code to print triangle stars

rows = input("Enter the number of line \n ")
rows = int (rows)
for i in range (0, rows):
for j in range(0, i + 1):
print("*", end=' ')
print("\r")


2) Second code to print triangle stars


for x in range(int(input("Enter the number of line \n"))+1):
print(x * "*")