Помогите пожалуйста с решением. Дано:
Write a function, persistence, that takes in a positive parameter num and returns its multiplicative persistence, which is the number of times you must multiply the digits in num until you reach a single digit.
For example:
persistence(39) => 3 # Because 3*9 = 27, 2*7 = 14, 1*4=4
# and 4 has only one digit.
Мой код, в котором у меня удалось умножить числа аргумента функции, но только один раз. Не знаю как сделать, чтоб полученный результат снова умножался и так до того момента пока в resultat не будет содержать только 1 цифру.
PythonВыделить код
1
2
3
4
5
6
7
8
9
10
11
def persistence(n): # your code num = str(n) resultat = [] for i in num: resultat.append(int(i)) resultat = reduce(lambda x, y: x * y, resultat) return resultat
Спасибо!