fork download
  1. class Property:
  2. def __init__(self, square_feet='', beds='',
  3. baths='', **kwargs):
  4. super().__init__(**kwargs)
  5. self.square_feet = square_feet
  6. self.num_bedrooms = beds
  7. self.num_baths = baths
  8.  
  9. def display(self):
  10. print("PROPERTY DETAILS")
  11. print("================")
  12. print("square footage: {}".format(self.square_feet))
  13. print("bedrooms: {}".format(self.num_bedrooms))
  14. print("bathrooms: {}".format(self.num_baths))
  15. print()
  16.  
  17. def prompt_init():
  18. return dict(square_feet=input("Enter the square feet: "),
  19. beds=input("Enter number of bedrooms: "),
  20. baths=input("Enter number of baths: "))
  21. prompt_init = staticmethod(prompt_init)
  22.  
  23. class Apartment(Property):
  24. valid_laundries = ("coin", "ensuite", "none")
  25. valid_balconies = ("yes", "no", "solarium")
  26. def __init__(self, balcony='', laundry='', **kwargs):
  27. super().__init__(**kwargs)
  28. self.balcony = balcony
  29. self.laundry = laundry
  30. def display(self):
  31. super().display()
  32. print("APARTMENT DETAILS")
  33. print("laundry: %s" % self.laundry)
  34. print("has balcony: %s" % self.balcony)
  35. def prompt_init():
  36. parent_init = Property.prompt_init()
  37. laundry = get_valid_input("What laundry facilities does the property have? ",Apartment.valid_laundries)
  38. balcony = get_valid_input("Does the property have a balcony? ",Apartment.valid_balconies)
  39. parent_init.update({
  40. "laundry": laundry,
  41. "balcony": balcony
  42. })
  43. return parent_init
  44. prompt_init = staticmethod(prompt_init)
  45.  
  46. class House(Property):
  47. valid_garage = ("attached", "detached", "none")
  48. valid_fenced = ("yes", "no")
  49.  
  50. def __init__(self, num_stories='',
  51. garage='', fenced='', **kwargs):
  52. super().__init__(**kwargs)
  53. self.garage = garage
  54. self.fenced = fenced
  55. self.num_stories = num_stories
  56.  
  57. def display(self):
  58. super().display()
  59. print("HOUSE DETAILS")
  60. print("# of stories: {}".format(self.num_stories))
  61. print("garage: {}".format(self.garage))
  62. print("fenced yard: {}".format(self.fenced))
  63.  
  64. def prompt_init():
  65. parent_init = Property.prompt_init()
  66. fenced = get_valid_input("Is the yard fenced? ",
  67. House.valid_fenced)
  68. garage = get_valid_input("Is there a garage? ",
  69. House.valid_garage)
  70. num_stories = input("How many stories? ")
  71.  
  72. parent_init.update({
  73. "fenced": fenced,
  74. "garage": garage,
  75. "num_stories": num_stories
  76. })
  77. return parent_init
  78.  
  79. class Purchase:
  80. def __init__(self,price = "", taxes = "",**kwargs):
  81. super().__init__(**kwargs)
  82. self.price = price
  83. self.taxes = taxes
  84. def display(self):
  85. super().display()
  86. print("PURCHASE DETAILS")
  87. print("selling price: {}".format(self.price))
  88. print("estimated taxes: {}".format(self.taxes))
  89.  
  90. def prompt_init(self):
  91. return dict(
  92. price = input("What is the selling price?"),
  93. taxes = input("What are the estimated taxes"))
  94. prompt_init = staticmethod(prompt_init)
  95.  
  96. class Rental:
  97. def __init__(self, furnished='', utilities='',
  98. rent='', **kwargs):
  99. super().__init__(**kwargs)
  100. self.furnished = furnished
  101. self.rent = rent
  102. self.utilities = utilities
  103.  
  104. def display(self):
  105. super().display()
  106. print("RENTAL DETAILS")
  107. print("rent: {}".format(self.rent))
  108. print("estimated utilities: {}".format(
  109. self.utilities))
  110. print("furnished: {}".format(self.furnished))
  111.  
  112. def prompt_init():
  113. return dict(
  114. rent=input("What is the monthly rent? "),
  115. utilities=input(
  116. "What are the estimated utilities? "),
  117. furnished = get_valid_input(
  118. "Is the property furnished? ",
  119. ("yes", "no")))
  120. prompt_init = staticmethod(prompt_init)
  121.  
  122. class HouseRental(Rental,House):
  123. def prompt_init():
  124. init = House.prompt_init()
  125. init.update(Rental.prompt_init())
  126. return init
  127. prompt_init = staticmethod(prompt_init)
  128.  
  129. class ApartmentRental(Rental,Apartment):
  130. def prompt_init():
  131. init = Apartment.prompt_init()
  132. init.update(Rental.prompt_init())
  133. return init
  134. prompt_init = staticmethod(prompt_init)
  135.  
  136. class ApartmentPurchase(Purchase, Apartment):
  137. def prompt_init():
  138. init = Apartment.prompt_init()
  139. init.update(Purchase.prompt_init())
  140. return init
  141. prompt_init = staticmethod(prompt_init)
  142.  
  143. class HousePurchase(Purchase, House):
  144. def prompt_init():
  145. init = House.prompt_init()
  146. init.update(Purchase.prompt_init())
  147. return init
  148. prompt_init = staticmethod(prompt_init)
  149.  
  150. class Agent:
  151. def __init__(self):
  152. self.property_list = []
  153.  
  154. def display_properties(self):
  155. for property in self.property_list:
  156. property.display()
  157.  
  158. type_map = {
  159. ("house", "rental"): HouseRental,
  160. ("house", "purchase"): HousePurchase,
  161. ("apartment", "rental"): ApartmentRental,
  162. ("apartment", "purchase"): ApartmentPurchase
  163. }
  164. def add_property(self):
  165. property_type = get_valid_input(
  166. "What type of property? ",
  167. ("house", "apartment")).lower()
  168. payment_type = get_valid_input(
  169. "What payment type? ",
  170. ("purchase", "rental")).lower()
  171. PropertyClass = self.type_map[
  172. (property_type, payment_type)]
  173. init_args = PropertyClass.prompt_init()
  174. self.property_list.append(PropertyClass(**init_args))
  175.  
  176. def get_valid_input(input_string, valid_options):
  177. input_string += " ({}) ".format(", ".join(valid_options))
  178. response = input(input_string)
  179. while response.lower() not in valid_options:
  180. response = input(input_string)
  181. return response
Success #stdin #stdout 0.03s 8968KB
stdin
Standard input is empty
stdout
Standard output is empty