Advertisement
AntonioVillanueva

Un numero Feliz

Apr 8th, 2020
489
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.48 KB | None | 0 0
  1. #!/usr/bin/python
  2. # -*- coding: latin-1 -*-
  3. import sys
  4. import math
  5.  
  6. def feliz(x):
  7.     """ analiza si es un numero feliz """
  8.     memoria=[]
  9.     r=0
  10.    
  11.     while x!='1' and not (x in memoria):
  12.         memoria.append(x) # x en la memoria por si se repite    
  13.         for n in x:
  14.             r+=int (n)**2
  15.                
  16.         x=str(r) #crea el nuevo numero de entrada  
  17.         r=0
  18.     return x
  19.            
  20. n = int(input()) #n numeros a probar
  21.  
  22. for i in range(n):
  23.     x = input()
  24.     print (str(x)+" "+ (':)' if feliz(x)=='1' else ':(' ) )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement