楼房销售系统代码python
时间: 2023-07-23 10:28:49 浏览: 57
以下是一个简单的楼房销售系统的 Python 代码:
```python
class House:
def __init__(self, address, price, area, rooms):
self.address = address
self.price = price
self.area = area
self.rooms = rooms
class Salesman:
def __init__(self, name, commission):
self.name = name
self.commission = commission
def sell_house(self, house, buyer):
if buyer.budget >= house.price:
buyer.budget -= house.price
self.commission += house.price * 0.1
print("Congratulations, " + buyer.name + "! You have successfully purchased " + house.address + " for " + str(house.price) + " dollars.")
else:
print("Sorry, " + buyer.name + "! You cannot afford " + house.address + ".")
class Buyer:
def __init__(self, name, budget):
self.name = name
self.budget = budget
salesman = Salesman("John", 0)
house1 = House("123 Main St", 500000, 2000, 4)
house2 = House("456 Elm St", 300000, 1500, 3)
house3 = House("789 Oak St", 700000, 2500, 5)
buyer1 = Buyer("Alice", 600000)
buyer2 = Buyer("Bob", 400000)
salesman.sell_house(house1, buyer1) # Congratulations, Alice! You have successfully purchased 123 Main St for 500000 dollars.
salesman.sell_house(house2, buyer2) # Sorry, Bob! You cannot afford 456 Elm St.
salesman.sell_house(house3, buyer2) # Congratulations, Bob! You have successfully purchased 789 Oak St for 700000 dollars.
```
这个系统包含三个类:House、Salesman 和 Buyer。House 类表示一栋房子,包含地址、价格、面积和房间数等属性。Salesman 类表示销售员,包含名字和佣金等属性,以及一个 sell_house 方法,用于销售房子。Buyer 类表示买家,包含名字和预算等属性。在主程序中,创建了三个 House 对象和两个 Buyer 对象,然后调用 Salesman 的 sell_house 方法进行销售。如果买家的预算足够支付房子的价格,销售员会计算佣金并打印一条祝贺消息;否则会打印一条失败消息。