# Program to find average salary excluding the minimum and maximum salary in Python

PythonServer Side ProgrammingProgramming

Suppoe we have an array with distinct elements called salary where salary[i] is the salary of ith employee. We have to find the average salary of employees excluding the minimum and maximum salary.

So, if the input is like salary = [8000,6000,2000,8500,2500,4000], then the output will be 5125.0, as the minimum and maximum salary values are 2000 and 8500, so excluding them the average salary values are [8000,6000,2500,4000] so the average is (8000 + 6000 + 2500 + 4000)/4 = 5125.

To solve this, we will follow these steps −

• delete minimum of salary from salary

• delete maximum of salary from salary

• return sum of the salary values / number of elements in salary after removal

## Example (Python)

Let us see the following implementation to get better understanding −

Live Demo

def solve(salary):
salary.remove(min(salary))
salary.remove(max(salary))
return sum(salary)/len(salary)

salary = [8000,6000,2000,8500,2500,4000]
print(solve(salary))

## Input

[8000,6000,2000,8500,2500,4000]

## Output

5125.0
Updated on 17-May-2021 12:14:34