Advertisement
pacho_the_python

Untitled

Jul 11th, 2022
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.18 KB | None | 0 0
  1. class Seller:
  2.     def __init__(self, seller_name, budget):
  3.         self.seller_name = seller_name
  4.         self.budget = budget
  5.         self.buildings_for_sale = []
  6.  
  7.     def add_building(self, building, price):
  8.         if price > self.budget:
  9.             return "You haven't enough money to buy this building."
  10.  
  11.         self.buildings_for_sale.append(building)
  12.         self.budget -= price
  13.         return f"You add building {building.name} with {building.floors} floors for sale."
  14.  
  15.     def sell(self, building_name, amount):
  16.         for building in self.buildings_for_sale:
  17.             if building.name == building_name:
  18.                 self.budget += amount
  19.                 self.buildings_for_sale.remove(building)
  20.                 return f"You sold `{building.name}` for {amount}$"
  21.         return "You haven't this building in your list."
  22.  
  23.     def building_status(self):
  24.         result = "Buildings status:\n"
  25.         for building in self.buildings_for_sale:
  26.             result += f"==== '{building.name}' " + f"with {building.floors} floors" + "\n"
  27.         return result.strip()
  28.  
  29.     def current_budget(self):
  30.         return f"{self.seller_name}'s budget is {self.budget}$"
  31.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement