science facts and news

Monday, July 5, 2021

Given n, take the sum of the digits of n and continue until it reaches to single-digit - Codewars solution(Python)

def digital_root(n):
    x = sum(int(ifor i in str(n))
    if x > 9:
        return digital_root(x)
    return x


print(digital_root(2333))

No comments:

Post a Comment

About Me

Kohalpur, Banke, Nepal
Hi, I'm Roshan , a student just trying to explore the world of programming