Halooo! Today I’ll be teaching you how to find the second largest value in a list. The conditions -
-
Write a Python program that prints the second largest value in a list.
-
If the list is empty or only has one element, print None.SSS
To do this, we’ll have to make a list and then sort it and then we use the if statement and else.
Input:
lista = [1, 4, 8, 9, 100, 200, 30]
lista.sort()
if len(lista) > 1:
print(lista[-2])
else:
print("None")
Output -
100