Python >> Programma Python >  >> Python

Programma Python per stampare il modello di numeri della freccia sinistra

Scrivi un programma Python per stampare il modello di numeri della freccia sinistra usando for loop.

rows = int(input("Enter Left Arrow of Numbers Pattern Rows = "))

print("====The Left Arrow Numbers Pattern====")

for i in range(rows, 0, -1):
    for j in range(i, 0, -1):
        print(j, end = ' ')
    print()
    
for i in range(2, rows + 1):
    for j in range(i, 0, -1):
        print(j, end = ' ')
    print()

Questo esempio Python stampa la freccia sinistra del modello dei numeri usando un ciclo while.

rows = int(input("Enter Left Arrow of Numbers Pattern Rows = "))

print("====The Left Arrow Numbers Pattern====")
i = rows

while(i >= 1):
    j = i
    while(j >= 1):
        print(j, end = ' ')
        j = j - 1
    print()
    i = i - 1

i = 2   
while(i <= rows):
    j = i
    while(j >= 1):
        print(j, end = ' ')
        j = j - 1
    print()
    i = i + 1
Enter Left Arrow of Numbers Pattern Rows = 12
====The Left Arrow Numbers Pattern====
12 11 10 9 8 7 6 5 4 3 2 1 
11 10 9 8 7 6 5 4 3 2 1 
10 9 8 7 6 5 4 3 2 1 
9 8 7 6 5 4 3 2 1 
8 7 6 5 4 3 2 1 
7 6 5 4 3 2 1 
6 5 4 3 2 1 
5 4 3 2 1 
4 3 2 1 
3 2 1 
2 1 
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 
9 8 7 6 5 4 3 2 1 
10 9 8 7 6 5 4 3 2 1 
11 10 9 8 7 6 5 4 3 2 1 
12 11 10 9 8 7 6 5 4 3 2 1