楼房销售系统

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是一个简单的楼房销售系统的 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 方法进行销售。如果买家的预算足够支付房子的价格,销售员会计算佣金并打印一条祝贺消息;否则会打印一条失败消息。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值