一个收租软件 python
时间: 2023-05-30 08:02:03 浏览: 70
以下是一个简单的 Python 收租软件,可以记录租赁信息和计算租金:
```python
import datetime
class Tenant:
def __init__(self, name, rent):
self.name = name
self.rent = rent
self.payments = []
def make_payment(self, amount):
self.payments.append((datetime.date.today(), amount))
def get_balance(self):
total_paid = sum(payment[1] for payment in self.payments)
return self.rent - total_paid
class RentalProperty:
def __init__(self, address, rent):
self.address = address
self.rent = rent
self.tenants = []
def add_tenant(self, name):
self.tenants.append(Tenant(name, self.rent))
def get_tenant_balance(self, name):
for tenant in self.tenants:
if tenant.name == name:
return tenant.get_balance()
def make_payment(self, name, amount):
for tenant in self.tenants:
if tenant.name == name:
tenant.make_payment(amount)
def get_property_balance(self):
total_rent = len(self.tenants) * self.rent
total_paid = sum(tenant.get_balance() for tenant in self.tenants)
return total_rent - total_paid
property1 = RentalProperty("123 Main St", 1000)
property1.add_tenant("John")
property1.add_tenant("Mary")
property1.make_payment("John", 500)
property1.make_payment("Mary", 750)
print(property1.get_tenant_balance("John")) # 500
print(property1.get_property_balance()) # 750
```
这个程序创建了两个类:Tenant 和 RentalProperty。Tenant 类代表租户,包含租户的姓名、租金和支付历史。RentalProperty 类代表租赁物业,包含物业地址、租金和租户列表。它有方法来添加和检索租户,以及记录和检索租金支付。它还有一个方法来计算物业租金余额。在这个例子中,我们创建了一个物业,添加了两个租户,并记录了一些租金支付。我们还打印了 John 的租金余额和物业租金余额。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)