Skip to content

Commit e543a19

Browse files
Merge pull request #177 from dhanushrajvr/add-happy-number
Add Happy Number
2 parents e1b99c1 + 0373ff5 commit e543a19

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

math/Happy-Number/Happy-Number.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
print("🔢 Happy Number Checker 🔢")
2+
print("🎯 A happy number is a number which eventually reaches 1 when replaced repeatedly by the sum of the square of its digits.\n")
3+
4+
N = int(input("➡️ Enter a number: "))
5+
6+
seen = set()
7+
num = N
8+
while num != 1 and num not in seen:
9+
seen.add(num)
10+
num = sum((int(digit) ** 2) for digit in str(num))
11+
12+
if (num == 1):
13+
print(f"🔍 {N} is a happy number! ✅")
14+
else:
15+
print(f"🔍 {N} is not a happy number. ❌")

0 commit comments

Comments
 (0)