We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 03bdf3f + 4588e46 commit 0a1a4dfCopy full SHA for 0a1a4df
happy_num
@@ -0,0 +1,23 @@
1
+#isHappyNumber() will determine whether a number is happy or not
2
+def isHappyNumber(num):
3
+ rem = sum = 0;
4
+
5
+ #Calculates the sum of squares of digits
6
+ while(num > 0):
7
+ rem = num%10;
8
+ sum = sum + (rem*rem);
9
+ num = num//10;
10
+ return sum;
11
12
+num = 82;
13
+result = num;
14
15
+while(result != 1 and result != 4):
16
+ result = isHappyNumber(result);
17
18
+#Happy number always ends with 1
19
+if(result == 1):
20
+ print(str(num) + " is a happy number");
21
+#Unhappy number ends in a cycle of repeating numbers which contain 4
22
+elif(result == 4):
23
+ print(str(num) + " is not a happy number");
0 commit comments