Digital Root without loops Python

后端 未结 6 868
无人及你
无人及你 2021-01-25 07:58
def digit_sum(n):
    \'\'\'(int)->number
    Returns the sum of all the digits in the given integer, n\'\'\'
    if n<10:
        return n
    return n%10 + digit         


        
6条回答
  •  余生分开走
    2021-01-25 08:33

    {def MDR(n):
        '''
        this function returns multiplicative digital root.
        '''
        count, mdr = 0, n 
        while mdr > 9:
            m, digitsMul = mdr, 1
            while m:
                m, md = divmod(m, 10)
                digitsMul *= md
            mdr = digitsMul
            count += 1
        return count, mdr}
    

提交回复
热议问题