Repository navigation
Expand file tree
/
Copy pathtask_11.py
More file actions
48 lines (38 loc) · 1.65 KB
/
Copy pathtask_11.py
File metadata and controls
48 lines (38 loc) · 1.65 KB
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
"""
Реализуйте класс Dessert c геттерами и сеттерами name и calories, конструктором,
принимающим на вход name и calories (не обязательные параметры), а также двумя
методами is_healthy (возвращает true при условии калорийности десерта менее
200) и is_delicious (возвращает true для всех десертов).
"""
class Dessert:
def __init__(self, name=None, calories=None):
self.__calories = calories
self.__name = name
def is_healthy(self):
return True if self.__calories is not None and self.__calories<200 else False if self.__calories is not None else Exception("Attribute must be initialized before calling this method")
def is_delicious(self):
return True
@property
def calories(self):
if self.__calories is not None:
return self.__calories
else:
raise Exception("You didn't initialize the calories for the dessert object")
@property
def name(self):
if self.__name is not None:
return self.__name
else:
raise Exception("Attribute must be initialized before calling this method")
@calories.setter
def calories(self, calories):
if type(calories) is int:
self.__calories = calories
else:
raise Exception("Calories number has to be an integer type")
@name.setter
def name(self, name):
self.__name = name
dessert1 = Dessert("чизкейк", 234)
dessert1.calories = 123
print(dessert1.calories)