Created
September 19, 2019 02:31
-
-
Save rodpoblete/e3bdf0b2e577c27bf58cbb30ded722bf to your computer and use it in GitHub Desktop.
Se le pasa a la función un numero entero `n` y se debe calcular su *persistencia multiplicativa*. Si el número tiene un solo dígito deberá devolver `0`
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def persistence(n): | |
from functools import reduce # Es necesario importar esta libreria del sistema | |
l = [int(x) for x in str(n)] | |
if len(l) == 1: | |
return(0) | |
else: | |
count = 0 | |
while True: | |
l2 = reduce(lambda x, y: x * y, l) | |
l = [int(n) for n in str(l2)] | |
count += 1 | |
if len(l) == 1: | |
break | |
else: | |
continue | |
return(count) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment