-2
step = int(input('enter a step size to count down by '))
for i in range(0,31,step):
    print(i)

I would like to know how to make this loop count down instead of up like it currently does. Thanks. (edit): I had previously tried swapping the start and stop values, which didn't work. Then i tried making 'step' negative int the range function which didn't work. I wasn't aware that doing both of these things together was a viable solution. Thanks to everyone who posted in response

1 Answers1

0

Just move the start and end value and and negate the step value

step = int(input('enter a step size to count down by '))
for i in range(31, 0 ,-step):
    print(i)
Yassine Faris
  • 951
  • 6
  • 26