Advertisement
Guest User

Untitled

a guest
May 27th, 2018
729
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.37 KB | None | 0 0
  1.  
  2.  
  3.  
  4.  
  5. def get_valid_input(input_string, valid_options):
  6. input_string += " ({}) ".format(", ".join(valid_options))
  7. response = input(input_string)
  8. while response.lower() not in valid_options:
  9. response = input(input_string)
  10. return response
  11.  
  12.  
  13.  
  14. class Property:
  15. def __init__(self, square_feet='', beds='',
  16. baths='', **kwargs):
  17. super().__init__(**kwargs)
  18. self.square_feet = square_feet
  19. self.num_bedrooms = beds
  20. self.num_baths = baths
  21.  
  22.  
  23. def display(self):
  24. print("PROPERTY DETAILS")
  25. print("================")
  26. print("square footage: {}".format(self.square_feet))
  27. print("bedrooms: {}".format(self.num_bedrooms))
  28. print("bathrooms: {}".format(self.num_baths))
  29. print()
  30.  
  31. def prompt_init():
  32. return dict(square_feet=input("Enter the square feet: "),
  33. beds=input("Enter number of bedrooms: "),
  34. baths=input("Enter number of baths: "))
  35. prompt_init = staticmethod(prompt_init)
  36.  
  37.  
  38. class Apartment(Property):
  39. valid_launderies = ("coin", "ensuite", "none")
  40. valid_balconies = ("yes", "no", "solarium")
  41.  
  42.  
  43. def __init__(self, balcony='', laundry='', **kwargs):
  44. super().__init__(**kwargs)
  45. self.balcony = balcony
  46. self.laundry = laundry
  47.  
  48. def display(self):
  49. super().display()
  50. print("Apartment Details")
  51. print("laundry: %s" % self.laundry)
  52. print("has balcony: %s" % self.balcony)
  53.  
  54.  
  55.  
  56.  
  57. def prompt_init():
  58. parent_init = Property.prompt_init()
  59. laundry = get_valid_input("What laundry facilities does "
  60. "the property have? ",
  61. Apartment.valid_launderies)
  62. balcony = get_valid_input(
  63. "Does the property have a balcony? ",
  64. Apartment.valid_balconies)
  65. parent_init.update({
  66. "laundry": laundry,
  67. "balcony": balcony
  68. })
  69. return parent_init
  70. prompt_init = staticmethod(prompt_init)
  71.  
  72.  
  73. class House(Property):
  74. valid_garage = ("attached", "detached", "none")
  75. valid_fenced = ("yes", "no")
  76.  
  77.  
  78. def __init__(self, num_stories='',
  79. garage='', fenced='', **kwargs):
  80. super().__init__(**kwargs)
  81. self.garage = garage
  82. self.fenced = fenced
  83. self.num_stories = num_stories
  84.  
  85. def display(self):
  86. super().display()
  87. print("HOUSE DETAILS")
  88. print("# of stories: {}".format(self.num_stories))
  89. print("garage: {}".format(self.fenced))
  90. print("fenced yard: {}".format(self.fenced))
  91.  
  92. def prompt_init():
  93. parent_init = Property.prompt_init()
  94. fenced = get_valid_input("Is the yard fenced? ",
  95. House.valid_fenced)
  96. garage = get_valid_input("Is there a garage? ",
  97. House.valid_garage)
  98. num_stories = input("How many stories? ")
  99.  
  100. parent_init.update({
  101. "fenced": fenced,
  102. "garage": garage,
  103. "num_stories": num_stories
  104. })
  105. return parent_init
  106. prompt_init = staticmethod(prompt_init)
  107.  
  108.  
  109. class Purchase:
  110. def __init__(self, price='', taxes='', **kwargs):
  111. super().__init__(**kwargs)
  112. self.price = price
  113. self.taxes = taxes
  114.  
  115. def display(self):
  116. super().display()
  117. print("PURCHASE DETAILS")
  118. print("selling price: {}".format(self.price))
  119. print("estimated taxes: {}".format(self.taxes))
  120.  
  121. def prompt_init():
  122. return dict(
  123. price=input("What is the selling price? "),
  124. taxes=input("What are the estimated taxes? "))
  125. prompt_init = staticmethod(prompt_init)
  126.  
  127. class Rental:
  128. def __init__(self, furnished='', utilities='',
  129. rent='', **kwargs):
  130. super().__init__(**kwargs)
  131. self.furnished = furnished
  132. self.rent = rent
  133. self.utilities = utilities
  134.  
  135.  
  136. def display(self):
  137. super().display()
  138. print ("RENTAL DETAILS")
  139. print("rent: {}".format(self.rent))
  140. print("estimated utilities: {}".format(
  141. self.utilities))
  142. print("furnished: {}".format(self.furnished))
  143.  
  144. def prompt_init():
  145. return dict(
  146. rent=input("What is the monthly rent? "),
  147. utilities=input(
  148. "What are the estimated utilities? "),
  149. furnished = get_valid_input(
  150. "Is the property furnished? ",
  151. ("yes", "no")))
  152. prompt_init = staticmethod(prompt_init)
  153.  
  154.  
  155. class HouseRental(Rental, House):
  156.  
  157. def prompt_init():
  158. init = House.prompt_init()
  159. init.update(Rental.prompt_init())
  160. return init
  161. prompt_init = staticmethod(prompt_init)
  162.  
  163. class ApartmentRental(Rental, Apartment):
  164.  
  165. def prompt_init():
  166. init = Apartment.prompt_init()
  167. init.update(Rental.prompt_init())
  168. return init
  169. prompt_init = staticmethod(prompt_init)
  170.  
  171.  
  172. class ApartmentPurchase(Purchase, Apartment):
  173.  
  174. def prompt_init():
  175. init = Apartment.prompt_init()
  176. init.update(Purchase.prompt_init())
  177. return init
  178. prompt_init = staticmethod(prompt_init)
  179.  
  180. class HousePurchase(Purchase, House):
  181.  
  182. def prompt_init():
  183. init = House.prompt_init()
  184. init.update(Purchase.prompt_init())
  185. return init
  186. prompt_init = staticmethod(prompt_init)
  187.  
  188.  
  189. class Agent:
  190. def __init__(self):
  191. self.property_list = []
  192.  
  193. def display_properties(self):
  194. for property in self.property_list:
  195. property.display()
  196.  
  197. type_map = {
  198. ("house", "rental"): HouseRental,
  199. ("house", "purchase"): HousePurchase,
  200. ("apartment", "rental"): ApartmentRental,
  201. ("apartment", "purchase"): ApartmentPurchase
  202. }
  203.  
  204. def add_property(self):
  205. property_type = get_valid_input(
  206. "What type of property? ",
  207. ("house", "apartment")).lower()
  208. payment_type = get_valid_input(
  209. "What payment type? ",
  210. ("purchase", "rental")).lower()
  211.  
  212. PropertyClass = self.type_map[
  213. (property_type, payment_type)]
  214. init_args = PropertyClass.prompt_init()
  215. self.property_list.append(PropertyClass(**init_args))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement