-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpizzashop.py
39 lines (32 loc) · 1.13 KB
/
pizzashop.py
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
from pizza import Pizza
# This function shows a limitation on tool-assisted
# refactoring in a dynamic language like Python.
#
# When you rename the Pizza getPrice method to get_price,
# does it rename the method here?
# - if no type annotation on the pizza parameter, maybe not
# - if use type annotation ':Pizza' on the parameter, it should
def order_pizza(pizza):
"""Print a description of a pizza, along with its price."""
# create printable description of the pizza such as
# "small pizza with muschroom" or "small plain pizza"
description = pizza.size
if pizza.toppings:
description += " pizza with "+ ", ".join(pizza.toppings)
else:
description += " plain cheeze pizza"
print(f"A {description}")
print("Price:", pizza.getPrice())
if __name__ == "__main__":
pizza = Pizza('small')
pizza.addTopping("mushroom")
pizza.addTopping("tomato")
pizza.addTopping("pinapple")
order_pizza(pizza)
# a plain pizza
pizza2 = Pizza("medium")
order_pizza(pizza2)
# pizza with only one topping
pizza3 = Pizza("large")
pizza3.addTopping("seafood")
order_pizza(pizza3)