Skip to content

Commit 6e7745d

Browse files
committed
harshed number using function
1 parent ce04ae3 commit 6e7745d

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)