7.2k views
2 votes
When the union is reporting about the latest salary negotiations, they are presenting the average salary, the median salary, and the salary gap for the workers they represent. Write a program salary_revision.py that reads an arbitrary number of salaries (integers) and then reports the median and average salaries, and the salary gap. Ensure all values are integers (correctly rounded off).

1 Answer

1 vote

Final answer:

The program salary_revision.py can be written to calculate the median and average salaries and the salary gap for an arbitrary number of salaries provided. The program utilizes the 'statistics' module for calculating the required statistical measures.

Step-by-step explanation:

The program salary_revision.py can be written to calculate the median and average salaries and the salary gap for an arbitrary number of salaries provided. Here is the solution:

import statisticsdef salary_revision(salaries):
median_salary = statistics.median(salaries)
average_salary = round(statistics.mean(salaries))
salary_gap = max(salaries) - min(salaries)
return median_salary, average_salary, salary_gap

# Example usage
salaries = [33000, 64500, 28000, 54000, 72000, 68500, 69000, 42000, 54000, 120000, 40500]
median, average, gap = salary_revision(salaries)

print(f"Median Salary: {median}")
print(f"Average Salary: {average}")
print(f"Salary Gap: {gap}")

This program first imports the 'statistics' module, which provides functions for calculating median, mean, and other statistical measures.

The 'salary_revision' function takes a list of salaries as input and calculates the median salary, average salary (rounded to the nearest integer), and the salary gap (difference between the maximum and minimum salaries).

The example usage demonstrates how to use the function with the given salaries.

User Micahhoover
by
8.6k points