'How to repeat value in middle of loop? [closed]
When the loop reaches the max value I want to print it again and again for the number in max value, i.e. if max = 5 I want to reach the loop till 5 and the print 5 for 5 times and the continue in reverse order.
max=10
if max >= 0:
for i in range(1, max):
print(i)
if i == max:
for _ in range(5):
print(i)
else:
print("x")
for i in range(max, 0, -1):
print(i)
This is code I tried but it doesn't seem to repeat the max values
Solution 1:[1]
is this what you are looking?
max=5
if max >= 0:
for i in range(1, max+1):
print(i)
if i == max:
for i in range(max):
print(max)
else:
print("x")
for i in range(max, 0, -1):
print(i)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Vineesh Vijayan |
