0

How to start the iteration loop from 000 to 999 using while loop in python?  

x1=0
x2=999

while x1 <= x2:
    print (x1)
    x1 += 1

don't use for loop, just while loop

Pitto
  • 8,229
  • 3
  • 42
  • 51
Mhmoud Amsha
  • 252
  • 1
  • 2
  • 7

3 Answers3

0

If you're asking how to pad the number with zeros,

print(f'{x1:03}')
Bucket
  • 7,415
  • 9
  • 35
  • 45
0

You could use:

In [1538]: x1=0 
      ...: x2=999
      ...:  
      ...: while x1 <= x2: 
      ...:     print (str(x1).zfill(3)) 
      ...:     x1 += 1 
      ...:             

Prints something like this:

000
001
002
003
004
005
006
007
halfer
  • 19,824
  • 17
  • 99
  • 186
Mayank Porwal
  • 33,470
  • 8
  • 37
  • 58
0

You need something like this:

while x1 <= x2:
     print (f'{x1:03}')
     x1 += 1
Achilleus
  • 1,824
  • 3
  • 20
  • 40