Q. Write a function to return the second largest number from a list of numbers.

Answer :-

def large( lst ) :
    large = lst [ 0 ]
    sec = lst[ 0 ]
    for i in lst :
        if large <= i :
            large = i
        elif sec < i :
            sec = i
    return sec

lst = eval(input("Enter a list :-"))
print( "Second Largest Number :-", large(lst) )

Output :-

Enter a list :-[1,2,3,4,5,6,7,8,9]
Second Largest Number :- 8

>>>

Enter a list :-[12,69,74,36,58,41,94,63,12,55]
Second Largest Number :- 74

>>> 


Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post