Print the following pattern. There is exactly one space between any two consecutive numbers on any line. There are no spaces at the end of any line.
1 2 1 1 2 3 2 1 1 2 3 4 3 2 1 1 2 3 4 5 4 3 2 1
this was the question
for i in range(1, 6):
# Print numbers in increasing order
for j in range(1, i + 1):
print(j, end=' ')
# Print numbers in decreasing order
for j in range(i - 1, 0, -1):
print(j, end=' ')
# Move to the next line
print()
when we print the above code I’m getting
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
the correct code should be:
for i in range(2, 6):
for j in range(1, i + 1):
print(j, end=' ')
for j in range(i - 1, 0, -1):
print(j, end=' ')
print()
The first loop will be 4 times, every time should begin with 1, so the range of the second loop starts with 1.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments