给定n个职员的信息,包括姓名、基本工资、浮动工资和支出,要求编写程序顺序输出每位职员的姓名和实发工资(实发工资=基本工资+浮动工资-支出)。
时间: 2023-05-01 13:01:10 浏览: 68
给定n个职员的信息,包括姓名、基本工资、浮动工资和支出,可以使用循环结构进行遍历输出。
示例代码:
```python
n = 3
employees = [
{"name": "张三", "base_salary": 5000, "bonus": 2000, "expenses": 1000},
{"name": "李四", "base_salary": 6000, "bonus": 3000, "expenses": 2000},
{"name": "王五", "base_salary": 7000, "bonus": 4000, "expenses": 3000},
]
for i in range(n):
name = employees[i]["name"]
base_salary = employees[i]["base_salary"]
bonus = employees[i]["bonus"]
expenses = employees[i]["expenses"]
real_salary = base_salary + bonus - expenses
print("姓名: ", name, "实发工资: ", real_salary)
```
其中, 循环结构中 `employees[i]["name"]` 即为第 i 个职员的姓名;`employees[i]["base_salary"]` 即为第 i 个职员的基本工资;`employees[i]["bonus"]` 即为第 i 个职员的浮动工资;`employees[i]["expenses"]` 即为第 i 个职员的支出。
阅读全文