Dremendo Tag Line

Input a number and find the largest digit in it using a function in Python

Function - Question 3

In this question, we will see how to input a number and find the largest digit in it in Python programming using a function. To know more about function click on the function lesson.

Q3) Write a program in Python to input a number and find the largest digit in it using a function.

Program

def largestdigit(num):
    ld=0
    while num>0:
        d=num%10
        if d>ld:
            ld=d
        num=num//10
    return ld


# main program
n=int(input('Enter a number '))
print('Largest Digit =',largestdigit(n))

Output

Enter a number 78261
Largest Digit = 8
video-poster