Define a function named "secondLarge" which take a list of numbers (integer) as parameter.
This function will then identify and return the 2nd largest number in the list. The function will
return smallest number if the parameter only contains two numbers. While the function will
return the only number if the list contain only single number. On some odd case, the function
will return -999 if the parameter contains other datatype i.e. string or floaat in the list.
FOR EXAMPLE:
• [1,2,3,4,5,6] returns 5
• [6,8,3,4,6] returns 6
• [53, 23] return 23
• [13] return 13
• [12, 'not number', 23] return -99220
def secondLarge(list):
for i in list:
if type(i) != int:
return -999
if len(list) >= 2:
list.remove(max(list))
return(max(list))
else:
return list[0]
print(secondLarge([1, 5, 7, 10, 2, 4]))
Comments
Leave a comment