Python Program - while loop patterns using numbers and special characters
# program for printing patterns
Program-1 :
row = 1
while(row<=5):
column = 1
while(column<=5):
print(row,end=' ')
column += 1
print()
row += 1
while(row<=5):
column = 1
while(column<=5):
print(row,end=' ')
column += 1
print()
row += 1
output-1 :
1 1 1 1 1
2 2 2 2 2
3 3 3 3 3
4 4 4 4 4
5 5 5 5 5
Program-2 :
row = 1
while(row<=5):
column = 1
while(column<=5):
print(column,end=' ')
column += 1
print()
row += 1
while(row<=5):
column = 1
while(column<=5):
print(column,end=' ')
column += 1
print()
row += 1
Output-2 :
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
Program-3 :
row = 1
while(row<=5):
column = 1
while(column<=row):
print(row,end=' ')
column += 1
print()
row += 1
Output-3 :
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5
Program-4 :
row = 1
while(row<=5):
column = 1
while(column<=row):
print(column,end=' ')
column += 1
print()
row += 1Output-4 :
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
Program-5 :
row = 5
while(row>=1):
column = 1
while(column<=row):
print(column,end=' ')
column += 1
print()
row -= 1Output-5 :
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1 Program-6 :
row = 5
while(row>=1):
column = 1
while(column<=row):
print(row,end=' ')
column += 1
print()
row -= 1Output-6 :
5 5 5 5 5 4 4 4 4 3 3 3 2 2 1Program-7 :
i = 1
while(i<=5):
j = 5
while(j>=i):
print('*',end=' ')
j -= 1
k = 1
while(k<=i):
print('#',end=' ')
k += 1
print()
i += 1Output-7 :
* * * * * # * * * * # # * * * # # # * * # # # # * # # # # #Program-8 :
# first half for the expected output
i = 1
while(i<=5):
j = 1
while(j<=i):
print('*',end=' ')
j += 1
print()
i += 1
# second half for the expected output
k = 1
while(k<=4):
l = 4
while(l>=k):
print('*',end=' ')
l -= 1
print()
k += 1Output-8 :
* * * * * * * * * * * * * * * * * * * * * * * * *
Comments