Skip to content

Commit 8b181a8

Browse files
authored
Merge pull request prabhupant#285 from shreyas1599/patch-1
Update sumofdigits.py
2 parents a40e638 + 19ffc10 commit 8b181a8

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

algorithms/math/sumofdigits.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
#This is to find the sum of digits of a number untill it is a single digit
2-
n=int(input()) #here n is the number
3-
if n%9!=0:
4-
print(n%9)
5-
else:
6-
print("9")
7-
#this method reduces time complexity by a factor of n and also without using any loop
1+
# This is to find the sum of digits of a number until it is a single digit
2+
3+
def sum_of_digits(n):
4+
n = int(input()) # here n is the number
5+
if n % 9 != 0:
6+
print(n % 9)
7+
else:
8+
print("9")
9+
10+
# This method reduces time complexity by a factor of n and also without using any loop
811

0 commit comments

Comments
 (0)