Найти - Пользователи
Полная версия: Задача с CODEWARS
Начало » Центр помощи » Задача с CODEWARS
1
Bopo6eu
Условие:

In this kata, you must create a digital root function.

A digital root is the recursive sum of all the digits in a number. Given n, take the sum of the digits of n. If that value has two digits, continue reducing in this way until a single-digit number is produced. This is only applicable to the natural numbers.

Мой код:

 def digital_root(n=1238142342342):
    while n > 10:
        b = 0
        c = str(n)
        for i in range(len(c)):
            a =  n % 10
            b += a
            n = n//10
        n = b
        print(n)
digital_root()

Test Results:
None should equal 7
None should equal 6
None should equal 2
None should equal 9
None should equal 9
None should equal 0


Что он от меня хочет???
py.user.next
У тебя return нет в функции. Когда return нет, функция выполняет return None.
Vigi
 def digital_root(n):
    return n if n < 10 else digital_root(sum(map(int, str(n))))
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB