Skip to content

Instantly share code, notes, and snippets.

@rodpoblete
Created September 19, 2019 02:31
Show Gist options
  • Save rodpoblete/e3bdf0b2e577c27bf58cbb30ded722bf to your computer and use it in GitHub Desktop.
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`
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