replace all 0's with 1 in a given integer In Python

              

        Replace all 0's with 1 in a given integer In Python

Input: 102405

Output: 112415

Program:

    # Python program to replace all 0’s with 1 in a given integer

    def re(n):

        if (n == 0):
            return 0;



    # Extract the last digit and change it if needed

        digit = n % 10

        if (digit == 0):

            digit = 1
        return re(int(n/10)) * 10 + digit

    n = int(input("Enter the number : "))

    print("Number after replacement : ",re(n))

    OutPut:
    Enter the number : 123034
    Number after replacement :  123134






















    No comments:

    Post a Comment