Find the Second Largest Number in a List
Helloo,
In this blog I will show you how to find the second largest number in a list.
I’ve included the instruction in my code first you make a list with numbers any order you like then you do (listname).sort() after that use if and else that’s all :))).
#The List
list_b = [6, 1, 3, 5]
#To sort the number in ascending order
list_b.sort()
#If to check if list_b bigger than 1
if len(list_b) > 1:
print('The second largest value is:', list_b[-2])
#Else in case list_b is smaller than 1
else:
print("None")
:3