Pattern #1:
1
1 2 1
1 2 3 2 1
1 2 3 4 3 2 1
1 2 3 4 5 4 3 2 1
code:-
n = 5
for i in range(1,n+1):
for j in range(1,–i):
print(j,end=” “)
for k in range(–i,0,-1):
print(k,end=” “)
print(“\n”)
Pattern #2:
5 4 3 2 1 1 2 3 4 5
5 4 3 2 2 3 4 5
5 4 3 3 4 5
5 4 4 5
5 5
code:-
n = 6
for i in range(0,n):
for j in range(n-1,i,-1):
print(j,end=” “)
for k in range(i+1,n):
print(k,end=” “)
print(“\n”)
Pattern #3:
5 5 5 5 5
4 4 4 4
3 3 3
2 2
1
code:-
n = 5
for i in range(n,0,-1):
for j in range(i):
print(i,end=” “)
print(“\n”)
Pattern #4:
1 2 3 4 5
2 2 3 4 5
3 3 3 4 5
4 4 4 4 5
5 5 5 5 5
code:-
n = 5
for i in range(1,n+1):
for j in range(1,n+1):
if j <= i:
print(i, end=’ ‘)
else:
print(j, end=’ ‘)
print()
Pattern #5:
5 5 5 5 5
5 5 5 5
5 5 5
5 5
5
5
5 5
5 5 5
5 5 5 5
5 5 5 5 5
code:-
n = 5
for i in range(n,0,-1):
for j in range(i):
print(n,end=” “)
print(“\n”)
for i in range(1,n+1):
for j in range(i):
print(n,end=” “)
print(“\n”)
Comments
Post a Comment
If you have any doubts, Please let me know