-
Notifications
You must be signed in to change notification settings - Fork 0
/
lab_3_Zabulskyy.py
425 lines (379 loc) · 12.5 KB
/
lab_3_Zabulskyy.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
class Property:
"""
contains number of bathrooms, bedrooms and square_feet
"""
def __init__(self, square_feet='', beds='', baths='', **kwargs):
"""
declare and assign properties
:param square_feet: str, size of apartment/house
:param beds: str, number of bedrooms
:param baths: str, number of bathrooms
:param kwargs: additional parameters
"""
super().__init__(**kwargs)
self.square_feet = square_feet
self.num_bedrooms = beds
self.num_baths = baths
def display(self):
"""
print all properties
:return: None
"""
print("\n================")
print("PROPERTY DETAILS")
print("================")
print("square footage: {}".format(self.square_feet))
print("bedrooms: {}".format(self.num_bedrooms))
print("bathrooms: {}".format(self.num_baths))
print()
def prompt_init():
"""
get arguments from input
:return: dict with inputted strings
"""
return dict(square_feet=input("Enter the square feet: "),
beds=input("Enter number of bedrooms: "),
baths=input("Enter number of baths: "))
prompt_init = staticmethod(prompt_init)
def get_valid_input(input_string, valid_options):
"""
change all input to valid format
input response till it is valid
:param input_string: text, which will be asked to user
:param valid_options: tuple, with which we will compare input
:return:
"""
input_string += " ({}) ".format((", ".join(valid_options)))
response = input(input_string)
while response.lower() not in valid_options:
response = input(input_string)
return response
class Apartment(Property):
"""
extends Property
info about Apartment
"""
valid_laundries = ("coin", "ensuite", "none")
valid_balconies = ("yes", "no", "solarium")
def __init__(self, balcony='', laundry='', **kwargs):
"""
contains info about balconies and laundries
:param balcony: str
:param laundry: str
:param kwargs: additional info
"""
super().__init__(**kwargs)
self.balcony = balcony
self.laundry = laundry
def display(self):
"""
output all info
:return: None
"""
super().display()
print("APARTMENT DETAILS")
print("laundry: {}".format(self.laundry))
print("has balcony: {}".format(self.balcony))
def prompt_init():
"""
get properties and update info
:return: dict
"""
parent_init = Property.prompt_init()
laundry = get_valid_input(
"What laundry facilities does "
"the property have? ",
Apartment.valid_laundries)
balcony = get_valid_input(
"Does the property have a balcony?",
Apartment.valid_balconies)
parent_init.update({
"laundry": laundry,
"balcony": balcony
})
return parent_init
prompt_init = staticmethod(prompt_init)
class House(Property):
"""
extends Property
info about House
"""
valid_garage = ("attached", "detached", "none")
valid_fenced = ("yes", "no")
def __init__(self, num_stories='',
garage='', fenced='', **kwargs):
"""
contains info about garage and fenced
:param num_stories: str (int)
:param garage: str
:param fenced: str
:param kwargs: additional info
"""
super().__init__(**kwargs)
self.garage = garage
self.fenced = fenced
self.num_stories = num_stories
def display(self):
"""
output all info
:return: None
"""
super().display()
print("HOUSE DETAILS")
print("# of stories: {}".format(self.num_stories))
print("garage: {}".format(self.garage))
print("fenced yard: {}".format(self.fenced))
def prompt_init():
"""
get info
:return: dict
"""
parent_init = Property.prompt_init()
fenced = get_valid_input("Is the yard fenced? ",
House.valid_fenced)
garage = get_valid_input("Is there a garage? ",
House.valid_garage)
num_stories = input("How many stories? ")
parent_init.update({
"fenced": fenced,
"garage": garage,
"num_stories": num_stories
})
return parent_init
prompt_init = staticmethod(prompt_init)
class Purchase(Property):
"""
info about price and taxes
"""
def __init__(self, price='', taxes='', **kwargs):
"""
contains info about price and taxes
:param price: str
:param taxes: str
:param kwargs: additional info
"""
super().__init__(**kwargs)
self.price = price
self.taxes = taxes
def display(self):
"""
output info
:return: None
"""
super().display()
print("PURCHASE DETAILS")
print("selling price: {}".format(self.price))
print("estimated taxes: {}".format(self.taxes))
def prompt_init():
"""
input info
:return: dict
"""
return dict(
price=input("What is the selling price? "),
taxes=input("What are the estimated taxes? "))
prompt_init = staticmethod(prompt_init)
class Rental:
"""
info about house if it is furnished or/and has utilities
"""
def __init__(self, furnished='', utilities='',
rent='', **kwargs):
"""
contains info if house is furnished or/and has utilities
:param furnished: str
:param utilities: str
:param rent: str
:param kwargs: additional info
"""
super().__init__(**kwargs)
self.furnished = furnished
self.rent = rent
self.utilities = utilities
def display(self):
"""
output info
:return: None
"""
super().display()
print("RENTAL DETAILS")
print("rent: {}".format(self.rent))
print("estimated utilities: {}".format(self.utilities))
print("furnished: {}".format(self.furnished))
def prompt_init():
"""
input info
:return: dict
"""
return dict(
rent=input("What is the monthly rent? "),
utilities=input("What are the estimated utilities? "),
furnished=get_valid_input("Is the property furnished? ",
("yes", "no")))
prompt_init = staticmethod(prompt_init)
class HouseRental(Rental, House):
"""
asks all stuff about house
"""
def prompt_init():
"""
updates info about house rental
:return: dict
"""
init = House.prompt_init()
init.update(Rental.prompt_init())
return init
prompt_init = staticmethod(prompt_init)
class ApartmentRental(Rental, Apartment):
"""
asks all stuff about apartment
"""
def prompt_init():
"""
updates info about apartment rental
:return: dict
"""
init = Apartment.prompt_init()
init.update(Rental.prompt_init())
return init
prompt_init = staticmethod(prompt_init)
class ApartmentPurchase(Purchase, Apartment):
"""
add an purchasing info to Apartment
"""
def prompt_init():
"""
add an purchasing info to Apartment
:return: dict
"""
init = Apartment.prompt_init()
init.update(Purchase.prompt_init())
return init
prompt_init = staticmethod(prompt_init)
class HousePurchase(Purchase, House):
"""
add an purchasing info to House
"""
def prompt_init():
"""
add an purchasing info to House
:return: dict
"""
init = House.prompt_init()
init.update(Purchase.prompt_init())
return init
prompt_init = staticmethod(prompt_init)
class Agent:
"""
holds a list of all properties, display those properties, and allows to create new ones
"""
type_map = {
("house", "rental"): HouseRental,
("house", "purchase"): HousePurchase,
("apartment", "rental"): ApartmentRental,
("apartment", "purchase"): ApartmentPurchase
}
def __init__(self):
"""
list of properties
"""
self.property_list = []
def display_properties(self, num=False):
"""
display all properties
"""
if num:
for property in self.property_list[num]:
property.display()
else:
for property in self.property_list:
for sub_property in property:
sub_property.display()
def add_property(self):
"""
add a new property
"""
property_type = get_valid_input(
"What type of property? ",
("house", "apartment")).lower()
payment_type = get_valid_input(
"What payment type? ",
("purchase", "rental")).lower()
PropertyClass = self.type_map[(property_type, payment_type)]
init_args = PropertyClass.prompt_init()
self.property_list.append([PropertyClass(**init_args)])
def delete_property(self):
"""
remove property from list
"""
really = input("are you sure? (type yes or no): ")
while really not in ["yes", "no"]:
really = input("expression is invalid, please type yes or no: ")
really = ["no", "yes"].index(really)
if not really:
return
which = int(input("set the number of option you would like to delete: "))
while which not in range(1, len(self.property_list) + 1):
which = int(input("this number is invalid, please set another: "))
self.display_properties()
sure = input("\nis it the property you want to delete? (type yes or no): ")
while sure not in ["yes", "no"]:
sure = input("expression is invalid, please type yes or no: ")
sure = ["no", "yes"].index(sure)
if sure:
self.property_list.remove(self.property_list[which - 1])
else:
self.delete_property()
def create_ad(self):
"""
create flashing ad with property
"""
from time import sleep
from os import system
if len(self.property_list) == 0:
print('there no properties to show')
return
which = int(input("set the number of option you would like to show: "))
while which not in range(1, len(self.property_list) + 1):
which = int(input("this number is invalid, please set another: "))
try:
print("press ctrl+C to stop")
sleep(1)
while True:
sleep(0.5)
system('cls')
sleep(0.2)
print("!!!BEST OFFER!!!")
self.display_properties()
except KeyboardInterrupt:
system('cls')
def welcome():
"""
interface, reading commands, contains all functions
"""
option = input("please, set the option (without brackets):\n"
"<add> to add a property\n"
"<display> to display all your properties\n"
"<delete> to delete some of your properties\n"
"<ad> to show an ad of one of your properties\n")
option = option.replace('<', '').replace('>', '').lower()
while option not in ['add', 'display', 'delete', 'ad']:
option = input('wrong command\n')
if option == 'add':
user.add_property()
print('\n--changes saved--\n')
elif option == 'display':
user.display_properties()
elif option == 'delete':
user.delete_property()
print('\n--changes saved--\n')
elif option == 'ad':
user.create_ad()
else:
print('something wrong, bye\n')
return
user = Agent()
while True:
from os import system
welcome()
print('\n-----------------\n')