-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Expand file tree
/
Copy pathpizza.py
More file actions
32 lines (24 loc) · 862 Bytes
/
pizza.py
File metadata and controls
32 lines (24 loc) · 862 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
class Pizza:
def __init__(self, toppings):
self.toppings = list(toppings)
def __repr__(self):
return f"Pizza({self.toppings})"
def add_topping(self, topping):
self.toppings.append(topping)
def remove_topping(self, topping):
if topping in self.toppings:
self.toppings.remove(topping)
@classmethod
def margherita(cls):
return cls(["mozzarella", "tomatoes"])
@classmethod
def prosciutto(cls):
return cls(["mozzarella", "tomatoes", "ham"])
@staticmethod
def get_size_in_inches(size):
"""Returns an approximate diameter in inches for common sizes."""
size_map = {"small": 8, "medium": 12, "large": 16}
return size_map.get(size, "Unknown size")
if __name__ == "__main__":
a_pizza = Pizza.margherita()
print(a_pizza, "😋🍕")