Python Program to find the smallest digit of a number using recursion


In this program, you will learn how to find the smallest digit of a number using recursion in Python.


123 => 1

435 => 3

Example: How to find the smallest digit of a number using recursion in Python

sm = 9


def largestdigit(n):
    global sm
    if n > 0:
        r = n % 10
        if sm > r:
            sm = r
        largestdigit(int(n / 10))
    return sm


n = int(input("Enter a number:"))

sm = largestdigit(n)

print("Smallest digit:", sm)

Output:

Enter a number:34215
Smallest digit: 1