Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
5 views2 pages

Nested Loops

The document contains various Python code snippets that demonstrate different patterns of printing numbers, asterisks, and letters using nested loops. Each code block illustrates a unique output format, such as increasing sequences, decreasing sequences, and character repetition. The examples range from printing simple numbers to more complex patterns involving characters from the alphabet.

Uploaded by

sara3694836948
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views2 pages

Nested Loops

The document contains various Python code snippets that demonstrate different patterns of printing numbers, asterisks, and letters using nested loops. Each code block illustrates a unique output format, such as increasing sequences, decreasing sequences, and character repetition. The examples range from printing simple numbers to more complex patterns involving characters from the alphabet.

Uploaded by

sara3694836948
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

In [1]: for i in range(1,6):

for j in range(1,i+1):
print(j, end=" ")
print()

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

In [2]: for i in range(1,6):


for j in range(1,i+1):
print(i, end=" ")
print()

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

In [23]: for i in range(5,0,-1):


for j in range(1,i+1):
print(j, end=" ")
print()

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

In [3]: for i in range(5,0,-1):


for j in range(i,0,-1):
print(j, end=" ")
print()

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

In [6]: for i in range(5,0,-1):


for j in range(1,i+1):
print(i, end=" ")
print()

5 5 5 5 5
4 4 4 4
3 3 3
2 2
1
In [3]: for i in range(1,6):
for j in range(1,i+1):
print("*", end=" ")
print()

*
* *
* * *
* * * *
* * * * *

In [6]: for i in range(5,0,-1):


for j in range(1,i+1):
print("*", end=" ")
print()

* * * * *
* * * *
* * *
* *
*

In [8]: for i in range(0,5):


for j in range(0,i+1):
print(chr(j+65), end=" ")
print()

A
A B
A B C
A B C D
A B C D E

In [14]: for i in range(0,5):


for j in range(0,i+1):
print(chr(i+65), end=" ")
print()

A
B B
C C C
D D D D
E E E E E

In [21]: for i in range(0,5):


for j in range(5,i,-1):
print(chr(i+65), end=" ")
print()

A A A A A
B B B B
C C C
D D
E

You might also like