用python写一个企业差旅费报销程序,并输出费用超标部分
时间: 2024-11-15 20:20:42 浏览: 32
用Python写一个模拟qq聊天小程序的代码实例
在Python中编写一个简单的差旅费报销程序,我们可以假设有以下几个类:员工、部门和公司,每个类都有相关的属性如姓名、职位、部门等。这里我们仅创建一个基础版本的报销处理逻辑,用于计算并输出超标部分。
```python
class Employee:
def __init__(self, name, position, department, expenses):
self.name = name
self.position = position
self.department = department
self.expenses = expenses
class Department:
def __init__(self, name, daily_expense_limit):
self.name = name
self.daily_expense_limit = daily_expense_limit
class Company:
def __init__(self, departments):
self.departments = departments
def calculate_excess(self):
for dept in self.departments:
total_expenses = sum(employee.expenses for employee in dept.employee_list)
if total_expenses > dept.daily_expense_limit:
excess_amount = total_expenses - dept.daily_expense_limit
print(f"{dept.name}部门超额金额:{excess_amount}")
# 示例数据
emp1 = Employee("张三", "经理", Department("销售部", 5000), [3000, 2500])
emp2 = Employee("李四", "职员", Department("市场部", 4000), [1800, 2000])
department_list = [Department("销售部", 5000), Department("市场部", 4000)]
company = Company(department_list)
# 计算和输出超标部分
company.calculate_excess()
```
在这个例子中,`calculate_excess`方法遍历各部门员工的总花费,如果超过每日限制,就打印出超出的部分。请注意这只是一个简化版的示例,实际的企业报销系统会更复杂,包括用户输入验证、审批流程等。
阅读全文