-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCustomPizza.py
58 lines (45 loc) · 1.47 KB
/
CustomPizza.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
from Pizza import Pizza
class CustomPizza(Pizza):
def __init__(self, size):
super().__init__(size)
self.toppingsList = []
if size == "S":
self.price = 8.00
elif size == "M":
self.price = 10.00
else:
self.price = 12.00
def addTopping(self, topping):
self.toppingsList.append(topping)
if self.size == "S":
self.price += 0.50
elif self.size == "M":
self.price += 0.75
else:
self.price += 1.00
def getPizzaDetails(self):
if len(self.toppingsList) == 0:
return "CUSTOM PIZZA\nSize: {}\nToppings:\nPrice: ${:.2f}\n".format(Pizza.getSize(self),self.price)
else:
toppings = ""
for i in self.toppingsList:
toppings += "\t" + "+ " + i + "\n"
return "CUSTOM PIZZA\nSize: {}\nToppings:\n{}\nPrice: ${:.2f}\n".format(Pizza.getSize(self),toppings[:-1],self.price)
##cp2 = CustomPizza("L")
##assert cp2.getPizzaDetails() == "CUSTOM PIZZA\nSize: L\nToppings:\nPrice: $12.00\n"
##cp1 = CustomPizza("S")
##assert cp1.getPizzaDetails() == \
##"CUSTOM PIZZA\n\
##Size: S\n\
##Toppings:\n\
##Price: $8.00\n"
##cp2 = CustomPizza("L")
##cp2.addTopping("extra cheese")
##cp2.addTopping("sausage")
##assert cp2.getPizzaDetails() == \
##"CUSTOM PIZZA\n\
##Size: L\n\
##Toppings:\n\
##\t+ extra cheese\n\
##\t+ sausage\n\
##Price: $14.00\n"