How can handle zero in such case

30 Views Asked by At
def rotate_num(number, shift):
    rotated_num = ''

    for digit in str(number):
        if digit.isdigit():
            start = ord('0')
            formula = (ord(digit) - start + shift) % 10 + start
            rotated_char = chr(formula)
            rotated_num += rotated_char
        else:
            rotated_num += digit

    return int(rotated_num)

My problem here is that everything works fine except if I want to use zero like (0261) i get an error, I try my best to solve this problem get stuck. Please any help.

I called the function

rotate_num(123,2) That means rotate by 2 and it works find, if Now I want to use zero I get an error how can I handle zero as an argument I get error.

0

There are 0 best solutions below