#44944: python


x__1 (~7年級~破防之頌_600題了)

學校 : 臺北市立麗山國中
編號 : 294220
來源 : [223.136.77.14]
最後登入時間 :
2025-01-21 13:45:02
a863. 3. Happy Numbers -- HP CodeWars2010 | From: [111.248.213.16] | 發表日期 : 2024-12-28 18:13

from sys import stdin
def is_unhappy(n):
 v=set()
 while not (n in v):
  v.add(n)
  tmp=0
  for i in str(n):
   tmp+=int(i)**2
  n=tmp
 if n==1:
  return False
 return True
for s in stdin:
 n=int(s)
 print(str(n)+' is a'+'n un'*is_unhappy(n)+' '*(1-is_unhappy(n))+'happy number')
 
ZeroJudge Forum