[Solved] How can I do this effectively? [closed]


One way to do it using sum(), list comprehension and recursion,

def simulated_sum(input):
    """This is a recursive function
    to find the simulated sum of an integer"""

    if len(str(input)) == 1:
        return input
    else:
        input_digits = [int(x) for x in str(input)]
        latest_sum = sum(input_digits)
        return simulated_sum(latest_sum)

input = int(input('Enter a number'))    
print(simulated_sum(input))

DEMO: https://rextester.com/WCBXIL71483

solved How can I do this effectively? [closed]