Half Pyramid Pattern In Python | Half Triangle Pattern In Python

Pattern printing in python is a little bit different from c/cpp because in python we have a slight change in the print function. Anyway, in this article, we will learn how to print half a Pyramid or half triangle pattern. This is a very basic and popular question of python.

 

Method-01

def ptrn(x):
    for i in range(x):
        print("*"*(i+1))
        
nmber = int(input("Enter Input: "))
ptrn(nmber)

 

Output:

Enter Input: 5
*
**
***
****
*****

 

Method-02

def ptrn(x):
    for i in range(x):
        for j in range(i+1):
            print("*",end='')
        print('r')
        
nmber = int(input("Enter Input: "))
ptrn(nmber)

 

Output:

Enter Input: 5
*
**
***
****
*****

 

Method-03

lines = input("Number of lines pattern wanted: ")
print(*[("*"*i) for i in range(1,int(lines)+1)],sep="n")

Output:

Enter Input: 5
*
**
***
****
*****

Leave a comment