

def plus_one(digits):
    carry = 1
    i = len(digits) - 1
    while carry == 1and i >= 0:
        carry = 1 if digits[i] + 1 > 9 else 0
        digits[i] = (digits[i] + 1) % 10
        i -= 1

    if carry == 1:
        digits.insert(0, 1)
    return digits


if __name__ == '__main__':
    print plus_one([9, 9, 9])
