Skip to content

Commit bdc063e

Browse files
committed
2.1 - count_digit.py
0 parents  commit bdc063e

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

Diff for: Mathematics/count_digits.py

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
def count_digit(n):
2+
""" Iterative Method """
3+
count = 0
4+
while n != 0:
5+
n //= 10
6+
count += 1
7+
return count
8+
""" Recursive Method """
9+
# if n == 0:
10+
# return 0
11+
# return 1 + count_digit(n//10)
12+
""" Conversion """
13+
# n = len(str(n))
14+
# return n
15+
16+
n = 23965465
17+
print("The number of digits in ", n, "is", count_digit(n))

0 commit comments

Comments
 (0)