📅  最后修改于: 2023-12-03 14:55:12.154000             🧑  作者: Mango
本程序可通过输入员工列表及其工资,返回工资低于平均工资的员工信息。
def below_avg_salary_employee():
"""
返回工资低于平均工资的员工信息
"""
# 输入员工数量
num = int(input("请输入员工数量:"))
employees = {} # 存储员工信息,例如:{"张三": 5000, "李四": 6000, ...}
# 输入员工姓名及其工资
for i in range(num):
name, salary = input(f"请输入第{i+1}个员工的姓名及其工资,以空格分隔:").split()
employees[name] = int(salary)
avg_salary = sum(employees.values()) / num
# 计算低于平均工资的员工信息
below_avg = []
for name, salary in employees.items():
if salary < avg_salary:
below_avg.append((name, salary))
# 返回低于平均工资的员工信息
return below_avg
# 示例
result = below_avg_salary_employee()
print("低于平均工资的员工信息:")
for name, salary in result:
print(f"姓名:{name}\t工资:{salary}")
低于平均工资的员工信息:
姓名:张三 工资:3000
姓名:李四 工资:2500