0% found this document useful (0 votes)
89 views13 pages

Patterns While Loop Part-1

The document contains 13 patterns of asterisks (*) and numbers printed in various geometric shapes, along with Python programs that generate each pattern. The programs use while loops with nested while loops and conditionals like if/else statements to control the printing of spaces and asterisks/numbers to build up the patterns row by row from top to bottom or bottom to top.

Uploaded by

vsnpradeep
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)
89 views13 pages

Patterns While Loop Part-1

The document contains 13 patterns of asterisks (*) and numbers printed in various geometric shapes, along with Python programs that generate each pattern. The programs use while loops with nested while loops and conditionals like if/else statements to control the printing of spaces and asterisks/numbers to build up the patterns row by row from top to bottom or bottom to top.

Uploaded by

vsnpradeep
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/ 13

Pattern 1:

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

Program 1:

r = 1

while r < 10:

c = 1

while c <= r:
print(c,end=" ")

c += 1

print()

r += 1
Pattern 2:

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

--------------------------------------------------------------------------

Program 2:

r = 1

while r <= 9:

c = 1

while c <= r:

print(r,end=" ")
c +=1

print()
r += 1
Pattern 3:

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

--------------------------------------------------------------------------

program 3:

r = 1

while r <= 9:

c = 1

while c <= r:

print(r,end=" ")
c +=1

print()
r += 1
Pattern 4 :

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

--------------------------------------------------------------------------

Program 4:

r = 9

while r >= 1:

c = 1

while c <= r:
print(r,end=' ')
c += 1

print()
r -= 1
Pattern 5 :

1
21
321
4321
54321
654321
7654321
87654321
987654321

-------------------------------------------------------------------
Program 5

r = 1

while r <= 9:
sp = 1

while sp <= 9 - r:
print(' ',end='')
sp += 1

c = r
while c >= 1:
print(c,end='')
c -= 1

print()

r += 1
Pattern 6

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

-------------------------------------------------------------

Program 6:

r = 1

while r <= 9:

sp = 1
while sp <= 9 - r:
print(' ',end=' ')
sp += 1

c = r
while c >= 1:
print(c,end=' ')
c -= 1
print()

r += 1
Pattern 7:
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5
6 6 6 6 6 6
7 7 7 7 7 7 7
8 8 8 8 8 8 8 8
9 9 9 9 9 9 9 9 9

Program 7:
r = 1

while r <= 9:

sp = 1

while sp <= 9 - r:
print(' ',end=' ')

sp += 1

c = r
while c >= 1:
print(r,end=' ')

c -= 1

print()

r += 1
Pattern 8:
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5
6 6 6 6 6 6
7 7 7 7 7 7 7
8 8 8 8 8 8 8 8
9 9 9 9 9 9 9 9 9

Program 8:
r = 1

while r <= 9:

sp = 1

while sp <= 9 - r:
print(' ',end=' ')

sp += 1

c = 1
while c <= r:
print(r,end=' ')

c += 1

print()

r += 1
Pattern 9:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
1 2 3 4 5 6
1 2 3 4 5 6 7
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7 8 9

------------------------------------ -----------
Program 9:

r = 1

while r <= 9:
sp = 1

while sp <= 9 - r:
print(' ',end=' ')

sp += 1

c = 1
while c <= r:
print(c,end=' ')
c += 1

print()

r += 1
Pattern 10:
*
* *
* * *
* * * *
* * * * *
* * * * * *
* * * * * * *
* * * * * * * *
* * * * * * * * *
* * * * * * * * * *
-------------------------------------------------- ---------------------
Program 10:

r = 1

while r <= 10:

c = 1

while c <= r:

print('*',end=' ')
c += 1

print()

r +=1
Pattern 11:

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

------------------------------------ ---------------------------
Program 11:

r = 10

while r >= 1:

c = 1

while c <= r:

print('*',end=' ')
c += 1

print()

r -=1
Pattern 12:

*
* *
* * *
* * * *
* * * * *
* * * * * *
* * * * * * *
* * * * * * * *
* * * * * * * * *
* * * * * * * * * *
---------------------------------------- --------------------------

Program 12:
r = 1

while r <= 10:

sp = 10
while sp > r:
print(' ',end=' ')
sp -= 1

c = 1

while c <= r:
print('*',end=' ')
c += 1

print()
r += 1
Pattern 13:
* * * * * * * * * *
* * * * * * * * *
* * * * * * * *
* * * * * * *
* * * * * *
* * * * *
* * * *
* * *
* *
*
-------------------------------- ---------
Program 13:
r = 10

while r >= 1:
sp = 10

while sp > r:
print(' ',end=' ')
sp -= 1

c = 1

while c <= r:
print('*',end=' ')
c += 1

print()
r -= 1

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy