Python: Print the following integers with zeros on the left of specified width
Print integers with left-padded zeros.
Write a Python program to print the following integers with zeros to the left of the specified width.
Sample Solution:
Python Code:
Sample Output:
Original Number: 3 Formatted Number(left padding, width 2): 03 Original Number: 123 Formatted Number(left padding, width 6): 000123
Flowchart:
For more Practice: Solve these Related Problems:
- Write a Python program to format a list of integers with leading zeros to a fixed width using str.zfill().
- Write a Python program to use f-string formatting to pad integers with zeros on the left up to a specified width.
- Write a Python program to iterate over a list of numbers and print each with zeros prepended to meet a target width.
- Write a Python program to convert integers to strings and apply zfill() to ensure uniform length with leading zeros.
Go to:
Previous: Write a Python program to print the following floating numbers with no decimal places.
Next: Write a Python program to print the following integers with '*' on the right of specified width.
Python Code Editor:
Contribute your code and comments through Disqus.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.