-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHarshadNumber.py
More file actions
30 lines (26 loc) · 1.27 KB
/
Copy pathHarshadNumber.py
File metadata and controls
30 lines (26 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# Programmer - python_scripts (Abhijith Warrier)
# PYTHON SCRIPT TO CHECK WHETHER THE ENTERED NUMBER IS HARSHAD NUMBER OR NOT
# In Mathematics, a number is called HARSHAD NUMBER, if the number is divisble by
# the sum of the digits present in the number.
# Defining a function called checkHarshadNo() with the number variable as the parameter
def checkHarshadNo(number):
# Storing the copy of the user-entered number in a new variable called number_copy
number_copy = number
# Declaring a new variable called sum_of_digits and setting it to 0
sum_of_digits = 0
# Calculating sum of the digits present in the number
for d in str(number):
sum_of_digits += int(d)
# Checking whether the user-entered number is divisible by the sum_of_digits value
if number % sum_of_digits == 0:
# printing the result
print("\n" + str(number) + " IS A HARSHAD NUMBER")
else:
# printing the result
print("\n" + str(number) + " IS NOT A HARSHAD NUMBER")
# Driver Code
if __name__ == '__main__':
# Prompting the user to enter the number to check and converting it into int type
num = int(input("ENTER THE NUMBER TO CHECK : "))
# Calling the checkHarshadNo() function with the user-entered number as parameter
checkHarshadNo(num)