In this Python program, we will learn how to count the number of digits in a number using recursion.
Here is the source code of the program to count the number of digits in a number using recursion.
# Python Program to Count Number of Digits in a Number Using Recursion
Count = 0
# Define a Recursive function
def Counting(Number):
global Count
if(Number > 0):
Count = Count + 1
Counting(Number//10)
return Count
# To take the input from the User
Number = int(input("Enter any Number: "))
Count = Counting(Number)
print("Number of Digits in a Given Number = %d" %Count)
Enter any Number: 5664196
Number of Digits in a Given Number = 7
Enter any Number: 54313566
Number of Digits in a Given Number = 8
Comments