Advertisements
Advertisements
प्रश्न
Write a program to print the following pattern:
| 1 2 1 2 3 2 1 2 3 4 3 2 1 2 3 4 5 4 3 2 1 2 3 4 5 |
टीपा लिहा
Advertisements
उत्तर
n = 5
for i in range (1, n + 1):
#This will print the space before the number
space = (n - i) * " "
print(space, end = " ")
#This for loop will print the decreasing numbers
for k in range(i, 1, -1):
print(k, end = " ")
#This for loop will print the increasing numbers
for j in range(1, i + 1):
print(j, end = " ")
#Print a new line after the space and numbers are printed
print()shaalaa.com
या प्रश्नात किंवा उत्तरात काही त्रुटी आहे का?
पाठ 6: Flow of Control - Exercise [पृष्ठ १४१]
