226k views
5 votes
python write a recursive function called digit count() that takes a positive integer as a parameter and returns the number of digits in the integer. hint: the number of digits increases by 1 whenever the input number is divided by 10.

1 Answer

7 votes

def digit_count(num):

if num < 10:

return 1

else:

return 1 + digit_count(num // 10)

User TheGeneral
by
8.6k points