Advertisements
Advertisements
Question
Write a program to print the following pattern:
| 1 2 3 4 5 1 2 3 4 1 2 3 1 2 1 |
Short/Brief Note
Advertisements
Solution
n = 5
for i in range (n, 0, -1):
# The space will increase on each iteration as i value will decrease
space = (n - i)*" "
print(space, end=" ")
#This for loop will print the increasing numbers
for j in range(1, i + 1):
print(j, end=" ")
print()shaalaa.com
Is there an error in this question or solution?
Chapter 6: Flow of Control - Exercise [Page 141]
