-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample05.py
More file actions
40 lines (30 loc) · 897 Bytes
/
example05.py
File metadata and controls
40 lines (30 loc) · 897 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
from food import Beverage
from person import Person
def main():
# Create an adult and a child
adult = Person("Dana", age=25)
child = Person("Eli", age=15)
# Create beverages
juice = Beverage("Orange Juice", contains_alcohol=False)
beer = Beverage("Beer", contains_alcohol=True)
# Wash hands before drinking
adult.wash_hands()
child.wash_hands()
# Non-alcoholic drink is allowed for both
juice.drink(adult)
juice2 = Beverage("Orange Juice", contains_alcohol=False)
juice2.drink(child)
# Alcoholic drink is blocked for child
beer.drink(child)
# Adult can drink alcohol
beer2 = Beverage("Beer", contains_alcohol=True)
beer2.drink(adult)
# JSON snapshots
adult.to_json()
child.to_json()
juice.to_json()
juice2.to_json()
beer.to_json()
beer2.to_json()
if __name__ == "__main__":
main()