Skip to content

Commit 656a26b

Browse files
authored
Update number_of_digits.py
1 parent 7749db8 commit 656a26b

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

maths/number_of_digits.py

+15-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
11
def num_digits(n):
2-
digits=0;
3-
while(n>0):
4-
n=n//10;
5-
digits=digits+1
2+
"""
3+
Find the number of digits in a number.
4+
>>> num_digits(12345)
5+
5
6+
>>> num_digits(123)
7+
3
8+
"""
9+
digits = 0
10+
while(n > 0):
11+
n = n // 10
12+
digits = digits + 1
613
return digits
714

8-
num=12345
9-
print("Number of digits in " + str(num) + " is : " + str(num_digits(num)))
15+
16+
if __name__ == "__main__":
17+
num = 12345
18+
print(num_digits(num)) # ===> 5

0 commit comments

Comments
 (0)