Computer Science, asked by killermafia367, 1 month ago

write a python program find the third largest/smallest number in a list.

Answers

Answered by shaziafaisalshamsi14
9

1)Third Largest element by comparison :

This is the most common method of finding the third largest element in a list since the program is built without using any bulit-in functions.This finds the Third largest element by comparison of the max elements 1,2 & 3.

Example :

third largest number

its the answer....

Attachments:
Answered by vishakasaxenasl
2

Answer:

Following the Python program finds the third largest/smallest number in a list.

arr = list(map(int,input().split()))

max3 ,min3= 0, 0

for i in range(1,4):

   max3 = max(arr)

   min3 = min(arr)

   if(i!=3):

      arr.remove(max1)

      arr.remove(min1)

print("The third maximum number of the list is: ",max3)

print("The third minimum number of the list is: "min3)

Explanation:

Let's understand the code above:

  • We have taken the user input list in the first line and created two variables for storing the third maximum and minimum element.
  • Now we iterate over the list three times and each time we find the minimum and maximum element using the pre-defined function min and max() of Python.
  • If the value of i is not 3 then we remove the maximum and minimum from the list.
  • In the last iteration, the third maximum and minimum are saved in the respective variables and we print them in the output.

#SPJ3

Similar questions