-2

I need a print function that writes Loop i / round, where both values i and round have to have at least four digits (12 -> 0012). It must have the format-method too.

I found the paste formatC and other ways to add leading zeroes but I can't make them work for this case..

It needs to be like this:

print('Loop {} / {}'.format('i', 'round'))

But with four digit numbers as I said.

Timus
  • 10,974
  • 5
  • 14
  • 28
  • Welome to SO! Could you please show what you have done so far the solve _your_ problem (not some vague statement)? You need to learn how to loop, which is a basic concept. SO isn't a tutorial replacement. – Timus Oct 02 '20 at 18:10

2 Answers2

0
number_str = str(a_number)
zero_filled_number = number_str.zfill(4)

a_number is 12. zero_filled_number will give you 0012

Paul Baiju
  • 419
  • 7
  • 20
0

Use print("{:02d}".format(1)) as found in this answer.

Joost Molenkamp
  • 106
  • 1
  • 5