-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.py
More file actions
52 lines (41 loc) · 1.02 KB
/
example.py
File metadata and controls
52 lines (41 loc) · 1.02 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
49
50
51
52
from food import Fruit, Meat
from meal import Meal
from person import Person, Vegetarian
def main():
# Create people
alice = Vegetarian("Alice", allergies=["peanut", "nut"])
ben = Person("Ben", is_diabetic=True)
# Create foods
apple = Fruit("Apple")
banana = Fruit("Banana")
steak = Meat("Steak")
# Wash hands before eating
alice.wash_hands()
ben.wash_hands()
# Wash and ripen fruit, then eat
apple.wash()
apple.ripen()
apple.eat(alice)
# Cook meat and try to eat (vegetarian blocked)
steak.cook()
steak.eat(alice)
# Diabetic fruit limit
banana.wash()
banana.ripen()
banana.eat(ben)
banana2 = Fruit("Banana")
banana2.wash()
banana2.ripen()
banana2.eat(ben)
# Meal prep and round-robin eating
meal = Meal([apple, banana, steak])
meal.prep()
meal.eat([alice, ben])
# JSON snapshots
alice.to_json()
ben.to_json()
apple.to_json()
steak.to_json()
meal.to_json()
if __name__ == "__main__":
main()