Part of the series

Several example codes

~1 min read • Updated Oct 7, 2025

Program Overview

This Python program reads an integer from the user and increases each digit by one.
If a digit becomes 10 after incrementing, it wraps around to 0.
The final result is displayed as a string of digits.


Python Code:


def increment_digits(n):
    result = ""
    for digit in str(n):
        new_digit = (int(digit) + 1) % 10
        result += str(new_digit)
    return result

# Run the program
n = int(input("Enter a number: "))
output = increment_digits(n)
print(f"Output: {output}")

Sample Output:


Enter a number: 5432  
Output: 6543

Enter a number: 7899  
Output: 8900

Step-by-Step Explanation:

- The input number is converted to a string to access each digit
- Each digit is converted to an integer and incremented by one
- If the result is 10, it wraps to 0 using % 10
- The new digit is added to the result string and printed at the end


Written & researched by Dr. Shahin Siami