count the number of digits in a number using recursion code example

Example 1: Python Program to Count Number of Digits in a Number Using Recursion

// Traditional Function
function (a){
  return a + 100;
}

// Arrow Function Break Down

// 1. Remove the word "function" and place arrow between the argument and opening body bracket
(a) => {
  return a + 100;
}

// 2. Remove the body brackets and word "return" -- the return is implied.
(a) => a + 100;

// 3. Remove the argument parentheses
a => a + 100;

Example 2: Python Program to Count Number of Digits in a Number Using Recursion

# Python Program to Count Number of Digits in a Number Using Recursion

Count = 0
def Counting(Number):
    global Count
    if(Number > 0):
        Count = Count + 1
        Counting(Number//10)
    return Count

Number = int(input("Please Enter any Number: "))
Count = Counting(Number)
print("\n Number of Digits in a Given Number = %d" %Count)

Tags:

Misc Example