- 1
Solve plz
this code is printing no. From 1000-9999 but how can i print 0001,0002,0003,0004 -----this series to 0999? https://code.sololearn.com/cs1dtWzJR61p/?ref=app
6 Réponses
+ 9
Use an f-string to print leading zeros
for i in range(1000):
print(f"{i:0>4}")
The :0>4 pads the output with zeros to make each number 4 digits long
https://code.sololearn.com/csYgTLLeAc0Q
+ 4
Aayush Jat The output of the print() function is ALWAYS a string. You can't print integers.
+ 4
AKSHAY🇮🇳 I'm sorry. I didn't realize that you gave that answer 6 hours before Francis Chege.
+ 3
You can try this but type of output will be string.
More details on "rjust" method which is used in the code:https://www.w3schools.com/JUMP_LINK__&&__python__&&__JUMP_LINK/ref_string_rjust.asp
https://code.sololearn.com/cbI7D235NziG/?ref=app
+ 2
David Ashton that's already covered in my answer
+ 1
for i in range(1000):
print(str(i).rjust(4, '0'))