Print Number Pattern in Python


Prev Tutorial Next Tutorial

Print Number Pattern in Python

You can write this program using for loop and while loop. Follow same concept like C programming only change syntax.

Print Number Pattern in Python

for i in range(7):
    print (str(i) + " ")*i

Output

	
1  
2 2  
3 3 3  
4 4 4 4  
5 5 5 5 5  
6 6 6 6 6 6 

Print number Pattern in Python

for i in range(1, 8 + 1):
    for j in range(i, 0, -1):
        print(j),
    print("")

Output

	
1
2 1
3 2 1
4 3 2 1
5 4 3 2 1
6 5 4 3 2 1
7 6 5 4 3 2 1
8 7 6 5 4 3 2 1

Print number Pattern in Python

for i in range(1, 9):
    for i in range(-1+i, -1, -1):
        print(format(2**i, "4d")),
    print

Output

	
1
2 1
4 2 1
8 4 2 1
16 8 4 2 1
32 16 8 4 2 1
64 32 16 8 4 2 1
128 65 32 16 8 4 2 1

Print number Pattern in Python

for i in range(1, 9):
    for i in range(0,i,1):
        print(format(2**i, "4d")),
    for i in range(-1+i, -1, -1):
        print(format(2**i, "4d")),   
    print

Output

	
1
1 2 1
1 2 4 2 1
1 2 4 8 4 2 1
1 2 4 8 16 32 16 8 4 2 1
1 2 4 8 16 32 64 32 16 8 4 2 1
1 2 4 8 16 32 64 128 64 32 16 8 4 2 1

Print number Pattern in Python

for i in range(1, 9):
    n = 34-(5*(i-1))+1
    print(" ")*n,
    for i in range(0,i,1):
        print(format(2**i, "4d")),
    for i in range(-1+i, -1, -1):
        print(format(2**i, "4d")),   
    print

Output

	
                            1
                         1 2 1
                      1 2 4 2 1
                   1 2 4 8 4 2 1
                1 2 4 8 16 8 4 2 1
           1 2 4 8 16 32 16 8 4 2 1
       1 2 4 8 16 32 64 32 16 8 4 2 1
1 2 4 8 16 32 64 128 64 32 16 8 4 2 1 

Prev Tutorial Next Tutorial

Google Advertisements
Download Projects

Google Adsense Advertisements

Buy 3 Year Old Domain, Tutorialday.com, SeosmoTools.com @$200

Buy This Ad Space @$50 per Month, Ad Size 300X250 Contact on: hitesh.xc@gmail.com WhatsApp no. 8882538826

Yahoo Advertisements