write program to print the following patterns-:

#star pattern 1
#*
#**
#***
#****
for i in range(1,5):
    for j in range (1,5):
        if j<=i:
            print("*",end='')
    else:
        print(" ",end='')
    print()

OUTPUT-
Python 3.8.5 (tags/v3.8.5:580fbb0, Jul 20 2020, 15:43:08) [MSC v.1926 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>> 
= RESTART: C:\Users\Dell\AppData\Local\Programs\Python\Python38-32\star pattern 1.py
* 
** 
*** 
**** 
>>> 
#star pattern 2
#****
#***
#***
#*
for i in range(1,5):
    for j in range(1,5):
        if j<=5-i:
            print("*",end='')
        else:
            print(" ",end='')
    print()
OUTPUT-
Python 3.8.5 (tags/v3.8.5:580fbb0, Jul 20 2020, 15:43:08) [MSC v.1926 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>> 
= RESTART: C:\Users\Dell\AppData\Local\Programs\Python\Python38-32\star pattern 2.py
****
*** 
**  
*   
>>> 
pattern 3
#5
#5 4
#5 4 3
#5 4 3 2
#5 4 3 2 1
for i in range(1,6):
    for j in range (5,0,-1):
        if j>=6-i:
            print(j,end=' ')
        else:
            print(" ",end=' ')
    print()
OUTPUT-
Python 3.8.5 (tags/v3.8.5:580fbb0, Jul 20 2020, 15:43:08) [MSC v.1926 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>> 
= RESTART: C:\Users\Dell\AppData\Local\Programs\Python\Python38-32\pattern 11 again.py
5         
5 4       
5 4 3     
5 4 3 2   
5 4 3 2 1 
>>> 

Leave a Reply

Back To Top