用python完成企业差旅费报销程序编写
时间: 2024-10-27 21:02:46 浏览: 39
Python是一种功能强大的编程语言,适合编写企业差旅费报销程序。下面是一个简单的例子,展示如何用Python创建一个基本的报销系统:
```python
class Employee:
def __init__(self, name):
self.name = name
self.expenses = []
def add_expense(self, expense):
self.expenses.append(expense)
print(f"{self.name} added an expense: {expense}")
def total_expenses(self):
return sum(self.expenses)
def submit_reimbursement_request(self, amount):
if amount <= self.total_expenses():
print(f"{self.name}'s reimbursement request of {amount} accepted.")
else:
print(f"{self.name}, your requested amount exceeds your current expenses.")
# 使用示例
employee = Employee("张三")
employee.add_expense(500) # 添加一次费用
employee.add_expense(700) # 再次添加费用
request_amount = employee.total_expenses() * 0.8 # 模拟打八折报销政策
employee.submit_reimbursement_request(request_amount)
```
这个程序定义了一个`Employee`类,包含姓名、费用列表以及提交报销请求的功能。员工可以添加费用,并在满足一定条件(例如总花费的80%以内)时提交报销请求。
阅读全文