[Solved] while loop and counting down from 20


This would do it

x = 20

while x > 0:
    print(x)
    x -= 1

If you need to include an if statement in the loop, you could do this instead.

x = 20

while True:
    print(x)
    x -= 1
    if x == 0:
      break

If you wanted to do this with a for loop, it would look like this:

for x in range(1, 20):
    print(x)

If you wanted to do it all in one line, you could do this. Just note that it doesn’t use a while loop or an if statement.

print("\n".join([str(x) for x in range(20, 0, -1)]))

7

solved while loop and counting down from 20