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
  • 32,567
  • 20
  • 113
  • 146
jack
  • 90
  • 1
  • 8

2 Answers2

2

You can use zero padding format with fixed width:

"{:04d}".format(number)
taras
  • 6,566
  • 10
  • 39
  • 50
0

You can do something like this, Hope this helps

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