Home > Backend Development > Python Tutorial > Day - Nested for loop and Pattern Programs

Day - Nested for loop and Pattern Programs

Mary-Kate Olsen
Release: 2024-12-26 20:16:11
Original
778 people have browsed it

Day - Nested for loop and Pattern Programs

for row in range(5):
    for col in range(5-row):
        print(col+1, end=" ")
    print()
Copy after login
1 2 3 4 5 
1 2 3 4 
1 2 3 
1 2 
1 
Copy after login
for row in range(5):
    for col in range(row+1):
        print(col+1, end=" ")
    print()
Copy after login
1 
1 2 
1 2 3 
1 2 3 4 
1 2 3 4 5 
Copy after login
for row in range(5):
    for col in range(5-row):
        print(5-col, end=" ")
    print()
Copy after login
5 4 3 2 1 
5 4 3 2 
5 4 3 
5 4 
5 
Copy after login
for row in range(5):
    for col in range(row+1):
        print(5-col, end=" ")
    print()
Copy after login
5 
5 4 
5 4 3 
5 4 3 2 
5 4 3 2 1
Copy after login
no=1
for row in range(5):
    for col in range(5-row):
        print(no, end=" ")
        no+=1
    print()
Copy after login
1 2 3 4 5 
6 7 8 9 
10 11 12 
13 14 
15 
Copy after login
for row in range(5):
    for col in range(5-row):
        print((col+1)*(row+1), end=" ")
    print()
Copy after login
1 2 3 4 5 
2 4 6 8 
3 6 9 
4 8 
5 
Copy after login
for row in range(5): 
    for col in range(5-row):
        print((col+1)+(row+1), end=' ')
    print()
Copy after login
2 3 4 5 6 
3 4 5 6 
4 5 6 
5 6 
6
Copy after login
for row in range(5): 
    for col in range(5-row):
        print((col+1)//(row+1), end=' ')
    print()
Copy after login
1 2 3 4 5 
0 1 1 2 
0 0 1 
0 0 
0 
Copy after login
for row in range(5): 
    for col in range(5-row):
        print((row+1)-(col+1), end=' ')
    print()
Copy after login
0 -1 -2 -3 -4 
1 0 -1 -2 
2 1 0 
3 2 
4
Copy after login
for row in range(5): 
    for col in range(5-row):
        print((row+1)-(col+1)+5, end=' ')
    print()
Copy after login
5 4 3 2 1 
6 5 4 3 
7 6 5 
8 7 
9
Copy after login
for row in range(5): 
    for col in range(5-row):
        print((row+1)+(col+1)-1, end=' ')
    print()
Copy after login
1 2 3 4 5 
2 3 4 5 
3 4 5 
4 5 
5 
Copy after login
for row in range(5):
    for col in range(5-row):
        print(col,end=' ')
    print()
Copy after login
0 1 2 3 4 
0 1 2 3 
0 1 2 
0 1 
0 
Copy after login
for row in range(5): 
    for col in range(4-row):
        print(col+1, end=' ')
    print()
Copy after login
1 2 3 4 
1 2 3 
1 2 
1 

Copy after login
for row in range(5): 
    for col in range(4-row):
        print(col+1, end=' ')
    print("*" , end=" ")
    print()
Copy after login
1 2 3 4 * 
1 2 3 * 
1 2 * 
1 * 
* 
Copy after login
for row in range(5): 
    for col in range(4-row):
        print(col+1, end=' ')
    for col in range(5):
        print("*" , end=" ")
    print()
Copy after login
1 2 3 4 * * * * * 
1 2 3 * * * * * 
1 2 * * * * * 
1 * * * * * 
* * * * * 
Copy after login
for row in range(5): 
    for col in range(4-row):
        print(col+1, end=' ')
    for col in range(5):
        print(col, end=" ")
    print()
Copy after login
1 2 3 4 0 1 2 3 4 
1 2 3 0 1 2 3 4 
1 2 0 1 2 3 4 
1 0 1 2 3 4 
0 1 2 3 4 
Copy after login
for row in range(5): 
    for col in range(4-row):
        print(" ", end=' ')
    for col in range(5):
        print(col+1, end=" ")
    print()
Copy after login
        1 2 3 4 5 
      1 2 3 4 5 
    1 2 3 4 5 
  1 2 3 4 5 
1 2 3 4 5 
Copy after login
for row in range(5): 
    for col in range(4-row):
        print(" ", end=' ')
    for col in range(row+1):
        print(col+1,end=' ')
    print()
Copy after login
        1 
      1 2 
    1 2 3 
  1 2 3 4 
1 2 3 4 5 
Copy after login
for row in range(5): 
    for col in range(4-row):
        print("", end=' ')
    for col in range(row+1):
        print(col+1,end=' ')
    print()
Copy after login
    1 
   1 2 
  1 2 3 
 1 2 3 4 
1 2 3 4 5 
Copy after login
for row in range(5): 
    for col in range(4-row):
        print(" ", end=' ')
    for col in range(row+1):
        print(5-col,end=' ')
    print()
Copy after login
        5 
      5 4 
    5 4 3 
  5 4 3 2 
5 4 3 2 1
Copy after login
for row in range(5): 
    for col in range(4-row):
        print(" ", end=' ')
    for col in range(row+1):
        print(5+col-row,end=' ')
    print()
Copy after login
        5 
      4 5 
    3 4 5 
  2 3 4 5 
1 2 3 4 5 
Copy after login
name='ABCDE'

for row in range(len(name)):
    for col in range(row+1):
        print(name[col], end=" ")
    print()
Copy after login
A 
A B 
A B C 
A B C D 
A B C D E 
Copy after login
name='PRITHA'

for row in range(len(name)):
    for col in range(6-row):
        print(name[col], end=" ")
    print()
Copy after login
P R I T H A 
P R I T H 
P R I T 
P R I 
P R 
P 
Copy after login
for row in range(5):
    for col in range(5-row):
        print((col+1)%2, end=" ")
    print()
Copy after login
1 0 1 0 1 
1 0 1 0 
1 0 1 
1 0 
1 
Copy after login
for row in range(5):
    for col in range(5-row):
        print(((col+1)+(row))%2, end=" ")
    print()
Copy after login
1 0 1 0 1 
0 1 0 1 
1 0 1 
0 1 
1 
Copy after login

The above is the detailed content of Day - Nested for loop and Pattern Programs. For more information, please follow other related articles on the PHP Chinese website!

source:dev.to
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template