1

How to input a number from 0 to 1000 and have python return a string that is always 4 characters long. for example: input 10 python should return 0010

smci
  • 29,564
  • 18
  • 109
  • 144
jack
  • 90
  • 1
  • 7

2 Answers2

2

You can use zero padding format with fixed width:

"{:04d}".format(number)
taras
  • 5,922
  • 10
  • 36
  • 48
0

You can do something like this, Hope this helps

num = 10
if num < 1000:
    print "%04d" % (num,)
Sachi.Dila
  • 1,026
  • 7
  • 14