Reducir número en Python

#!/bin/python # coding=utf-8 def sumar_numero(numero): suma, cont = 0,0 for num in str(numero): suma += int(num) if len(str(suma)) >= 2: suma = sumar_numero(suma) return suma def main(): lista = [12,14,16,17,22,33,45,100,120,220,234,245,321,388,402] for num in lista: print(num," ",sumar_numero(num)) if __name
De una lista de números enteros reducir cada elemento hasta lo máximo.

Si la entrada es 402 debe salir 6
Si la entrada es 121 debe salir 4

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.