-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodel.py
More file actions
39 lines (28 loc) · 823 Bytes
/
model.py
File metadata and controls
39 lines (28 loc) · 823 Bytes
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
import json
class FruitDB:
def __init__(self) -> None:
self.__data = None
def connect(self, data_file):
with open(data_file) as json_file:
self.__data = json.load(json_file)
def get_data(self, name):
for fruit in self.__data['Fruits']:
if fruit['name'] == name:
return fruit
def close(self):
pass
class FruitSalad:
def __init__(self) -> None:
self.__data = []
def add(self, fruit):
self.__data.append(fruit)
def contain(self, fruit):
if fruit in self.__data:
return True
else:
return False
def remove(self, fruit):
if self.contain(fruit):
self.__data.remove(fruit)
else:
raise NameError