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.
1 parent 6e7745d commit bbf380bCopy full SHA for bbf380b
Interview/Python/Solutions/140+ Basic Python Programs/Program 47/harshed_num_class.py
@@ -0,0 +1,22 @@
1
+class HarshadChecker:
2
+ def __init__(self, number):
3
+ self.number = number
4
+
5
+ def is_harshad(self):
6
+ digit_sum = sum(int(d) for d in str(self.number))
7
+ return self.number % digit_sum == 0
8
9
+# Input from user
10
+num = int(input("Enter a number: "))
11
+checker = HarshadChecker(num)
12
13
+if checker.is_harshad():
14
+ print(f"{num} is a Harshad Number.")
15
+else:
16
+ print(f"{num} is not a Harshad Number.")
17
18
19
+# ✅ Explanation:
20
+# We use a class to encapsulate the logic.
21
22
+# This is scalable for more number-related checks in the future.
0 commit comments