I want to iterate serial numbers from 000 to 999 in Python and save them to a txt file
JavaScript
x
8
1
import os
2
os.system ('clear')
3
4
lis9 = 01000
5
while lis9 < 01099 :
6
lis9 = lis9+1
7
print (lis9)
8
How do I start from a specific number and end at a specific number? The numbers start from zero
Each number begins on a new line
For example
JavaScript
1
8
1
01000
2
01001
3
.
4
01010
5
.
6
.
7
01099
8
Advertisement
Answer
Use f
string
JavaScript
1
4
1
with open('out.txt','w') as f:
2
for n in range(0,1000):
3
f.write(f'{n:03}n')
4
output (‘out.txt’)
JavaScript
1
10
10
1
000
2
001
3
002
4
003
5
6
996
7
997
8
998
9
999
10