Skip to content

Commit 1cfcc7d

Browse files
author
Joe Green
authored
Shortened code
Removed the old function is_harshad() and integrated the check in the new is_harshad()
1 parent 5903fef commit 1cfcc7d

1 file changed

Lines changed: 2 additions & 5 deletions

File tree

10_Harshad_Number/Python/wasi0013/HarshadNumber.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,12 @@
22
Harshad Number implementation
33
See: http://en.wikipedia.org/wiki/Harshad_number
44
"""
5-
def sum_digits(n):
5+
def is_harshad(n):
66
result=0
77
while n:
88
result+=n%10
99
n//=10
10-
return result
11-
12-
#returns True if n is harshad number or False otherwise
13-
def is_harshad(n): return (n%sum_digits(n)==0)
10+
return n%result == 0 # Return if the remainder of n/result is 0 else return False
1411

1512

1613
def main():

0 commit comments

Comments
 (0)