Computer Science, asked by augustyashukla394, 7 months ago

write a program to find the second largest number of a list of numbers​ in python

Answers

Answered by Anonymous
9

Answer:

here is a sample that might help you !

Explanation:

# Python program to find second largest

# number in a list

 

# list of numbers - length of  

# list should be at least 2

list1 = [10, 20, 4, 45, 99]

 

mx=max(list1[0],list1[1])  

secondmax=min(list1[0],list1[1])  

n =len(list1)

for i in range(2,n):  

   if list1[i]>mx:  

       secondmax=mx

       mx=list1[i]  

   elif list1[i]>secondmax and \

       mx != list1[i]:  

       secondmax=list1[i]

 

print("Second highest number is : ",\

     str(secondmax))

Output

Second highest number is :  45

Answered by kishanaravind07
0

listA= eval(input("Enter list1 :"))

listB = eval(input("Enter list2 :"))

len1 = len(lista)

len2 = len(listB)

for a in range (len1) :

ele = listA[a]

if ele in listB :

print("Overlapped")

break

#loop ends normally, not because of break

else :

print("Separated")

Solution.

Similar questions