This question already has an answer here:
The res will change like this 19,82,68,100,1. But when res == 1,the code will still run to isHappy(res). I don't know why it run like this.
I have debugged the code, but I don't know why it will still run to else even it meets res == 1;
def isHappy(n):
res = 0
for i in range(len(str(n))):
num = int(str(n)[i])
res += pow(num, 2)
if res == 1:
return True
else:
isHappy(res)
print(isHappy(19))
Excepted: True Actually: None
Aucun commentaire:
Enregistrer un commentaire