-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample04.py
More file actions
48 lines (37 loc) · 941 Bytes
/
example04.py
File metadata and controls
48 lines (37 loc) · 941 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
38
39
40
41
42
43
44
45
46
47
48
from food import Fruit, Meat
from person import Person, Vegetarian
def main():
# Create people with dietary rules
alice = Vegetarian("Alice", allergies=["peanut", "nut"])
ben = Person("Ben", is_diabetic=True)
# Create foods
apple = Fruit("Apple")
peanut_bar = Fruit("Peanut Bar")
steak = Meat("Steak")
# Wash hands before eating
alice.wash_hands()
ben.wash_hands()
# Allergy check (Alice)
peanut_bar.wash()
peanut_bar.ripen()
peanut_bar.eat(alice)
# Vegetarian check (Alice)
steak.cook()
steak.eat(alice)
# Diabetic fruit limit (Ben)
apple.wash()
apple.ripen()
apple.eat(ben)
apple2 = Fruit("Apple")
apple2.wash()
apple2.ripen()
apple2.eat(ben)
# JSON snapshots
alice.to_json()
ben.to_json()
apple.to_json()
peanut_bar.to_json()
steak.to_json()
apple2.to_json()
if __name__ == "__main__":
main()