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 ce04ae3 commit 6e7745dCopy full SHA for 6e7745d
Interview/Python/Solutions/140+ Basic Python Programs/Program 47/harshed_num_fun.py
@@ -0,0 +1,14 @@
1
+def is_harshad(num):
2
+ digit_sum = sum(int(digit) for digit in str(num))
3
+ return num % digit_sum == 0
4
+
5
+number = int(input("Enter a number: "))
6
7
+if is_harshad(number):
8
+ print(f"{number} is a Harshad Number.")
9
+else:
10
+ print(f"{number} is not a Harshad Number.")
11
+# ✅ Explanation:
12
+# str(num) converts the number to a string to easily iterate over digits.
13
14
+# The function is reusable and modular.
0 commit comments