
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
Program to find average salary excluding the minimum and maximum salary in Python
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 −
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
- Related Articles
- MySQL query to select maximum and minimum salary row?
- The average salary of 19 workers in a factory is ₹ 12,000 per month. If the salary of the manager is ₹ 42,000 per month, find the average monthly salary paid to all the employees.
- Write a program in Python to find the minimum age of an employee id and salary in a given DataFrame
- PMP® Certification Salary: Job and Salary Scope
- A man got 10% increase in his salary. If the new salary is Rs 1,54,000, find his original salary.
- A man got a 10% increase in his salary. If his new salary is Rs. 1,54,000, find his original salary.
- A person got a 10% increase in his salary. If his new salary is Rs 1,54,000, find his original salary.
- The salary of a man of 6 months is 9450. Find his monthly salary
- The annual salary of a worker in a factory is Rs. 1,36,146.00. Find her monthly salary.
- What is the Average Salary for a Digital Marketing Consultant in India?
- Program to find maximum average pass ratio in Python
- After getting an 8% increase in the salary, Mohan's new salary is ₹ 1,51,200. What was his original salary?
- C Program to calculate the salesmen salary with macro functions.
- Meeta saves $Rs.\ 4000$ from her salary. If this is $10 \%$ of her salary. What is her salary?
- A salary of a person was increased by 15%. If his salary now is Rs. 9936, then what was the initial salary?

Advertisements