finding the second largest element from a list in python

#here n is the number of elements to be inserted in list
n=int(input('enter size of list'))
li=[]
print('enter',n,'elements in list')
for i in range(n):                #taking n input from user and storing it in list
    li.append(input())
    li[i]=int(li[i])
max=li[0]
for i in range(n):               #findingthe largest element
    if(max<li[i]):
        max=li[i]
m=li[0]
for i in range(n):             #finding the second largest element
    if(max!=li[i]):
        if(m<li[i]):
            m=li[i]
print(m)                           #printing the second largest element

Comments

  1. Thanks for sharing this informative article on why Python?? If you want to Python development Training for your project. Please visit us.

    best software training institute in kukatpally
    best software training institute in hyderabad

    ReplyDelete

Post a Comment