aneliabogeva

Agency

Aug 16th, 2019
194
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from abc import ABC, abstractmethod
  2.  
  3. class Apartment(ABC):
  4. def __init__(self, id, rooms, baths, square_meters, price):
  5. self.id = id
  6. self.rooms = int(rooms)
  7. self.baths = int(baths)
  8. self.square_maters = float(square_meters)
  9. self.price = float(price)
  10. self.is_taken = False
  11.  
  12. @abstractmethod
  13. def __str__(self):
  14. return f"{self.rooms} rooms place with {self.bathrooms} bathroom/s.\n{self.square_meters} sq. meters for {self.price} lv."
  15.  
  16. class LivingApartment(Apartment):
  17. def __init__(self, id, rooms, baths, square_meters, price):
  18. Apartment.__init__(self, id, rooms, baths, square_meters, price)
  19.  
  20. def __str__(self):
  21. return Apartment.__str__(self)
  22.  
  23.  
  24. class OfficeApartment(Apartment):
  25. def __init__(self, id, rooms, baths, square_meters, price):
  26. Apartment.__init__(self, id, rooms, baths, square_meters, price)
  27.  
  28. def __str__(self):
  29. return Apartment.__str__(self)
  30.  
  31. data = input()
  32. apartments_list = []
  33. ids_list = list(map(lambda a: a.id, apartments_list))
  34.  
  35. while not data == "start_selling":
  36. try:
  37. current_apartment = eval(data)
  38. apartments_list.append(current_apartment)
  39. except Exception as ex:
  40. print(ex)
  41.  
  42. data = input()
  43.  
  44. data_list = input().split()
  45.  
  46. while not (data_list[0] == 'free' or data_list[0] == 'taken'):
  47. command = data_list[0]
  48. id = data_list[1]
  49.  
  50. if id in ids_list:
  51. current_apartment: Apartment = list(filter(lambda a: a.id == id, apartments_list))[0]
  52. if current_apartment.is_taken:
  53. print(f"Apartment with id - {id} is already taken!")
  54. elif command == 'rent' and isinstance(current_apartment, LivingApartment):
  55. print(f"Apartment with id - {id} is only for selling!")
  56. elif command == 'hire' and isinstance(current_apartment, OfficeApartment):
  57. print(f"Apartment with id - {id} is only for renting!")
  58. else:
  59. current_apartment.is_taken = True
  60. else:
  61. print(f"Apartment with id - {id} does not exist!")
  62.  
  63. data_list = input().split()
  64.  
  65. if data_list[0] == 'taken':
  66. taken_apartments_list = list(filter(lambda a: a.is_taken == True, apartments_list))
  67. for apartment in sorted(taken_apartments_list, key= lambda a: (a.price, -a.square_meters)):
  68. print(apartment)
  69.  
  70. elif data_list[0] == 'free':
  71. taken_apartments_list = list(filter(lambda a: a.is_taken == False, apartments_list))
  72. for apartment in sorted(taken_apartments_list, key= lambda a: (-a.price, a.square_meters)):
  73. print(apartment)
  74.  
  75. if len(taken_apartments_list) == 0:
  76. print("No information for this query")
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×