-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPizza.py
156 lines (104 loc) · 3.64 KB
/
Pizza.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
import csv
import datetime
with open("PizzaMenu.txt", "w") as menu:
menu.write("""* Please Choose a Pizza Base:
1: Classic
2: Margherita
3: FarmersPizza
4: PlainPizza
* and toppings of your choice:
11: Olives
12: Mushrooms
13: GoatCheese
14: Tuna
15: Onions
16: Corn
* Thank you!\n""")
# makes a dict out of the menu options:
with open("PizzaMenu.txt") as menu:
menu_dict = {}
for line in menu:
if "*" in line:
continue
(key, val) = line.split(": ")
val = val[:-1]
menu_dict[int(key)] = val
class Pizza:
def get_description(self):
return self.__class__.__name__
def get_cost(self):
return self.__class__.cost
class Margherita(Pizza):
cost = 35.0
def __init__(self):
self.description = "tomato sauce, Mozzarella and Basil"
class Classic(Pizza):
cost = 34.0
def __init__(self):
self.description = "tomato sauce, cheese and olives/mushrooms"
class FarmersPizza(Pizza):
cost = 36.0
def __init__(self):
self.description = "tomato sauce, extra cheese, eggplant, bell pepper and jalapeno"
class PlainPizza(Pizza):
cost = 34
def __init__(self):
self.description = "tomato sauce, cheese"
class Decorator(Pizza):
def __init__(self, topping):
self.component = topping
def get_cost(self):
return self.component.get_cost() + \
Pizza.get_cost(self)
def get_description(self):
return self.component.get_description() + \
' ' + Pizza.get_description(self)
class Olives(Decorator):
cost = 0.25
def __init__(self, topping):
Decorator.__init__(self, topping)
class Mushrooms(Decorator):
cost = 0.25
def __init__(self, topping):
Decorator.__init__(self, topping)
class GoatCheese(Decorator):
cost = 0.75
def __init__(self, topping):
Decorator.__init__(self, topping)
class Tuna(Decorator):
cost = 0.5
def __init__(self, topping):
Decorator.__init__(self, topping)
class Onions(Decorator):
cost = 0.25
def __init__(self, topping):
Decorator.__init__(self, topping)
class Corn(Decorator):
cost = 0.25
def __init__(self, topping):
Decorator.__init__(self, topping)
def main():
with open("PizzaMenu.txt") as cust_menu:
for l in cust_menu:
print(l, end="")
class_dict = {1: Classic, 2: Margherita, 3: FarmersPizza, 4: PlainPizza, 11: Olives, 12: Mushrooms, 13: GoatCheese, 14: Tuna, 15: Onions, 16: Corn}
code = input("Please choose the number of a basic pizza: ")
while code not in ["1", "2", "3", "4"]:
code = input("enter a valid number from 1-4 for the pizza base: ")
order = class_dict[int(code)]()
while code != "0":
code = input("Please choose toppings codes ('0' to exit when finished): ")
if code in ["11", "12", "13", "14", "15", "16"]:
order = class_dict[int(code)](order)
print("\n"+order.get_description().strip() +
": $" + str(order.get_cost()))
name = input("Enter your name: ")
ID = input("Enter your ID number: ")
credit_card = input("Enter your credit number: ")
credit_digits = input("Enter 3 digits on the back of your credit card: ")
time_of_order = datetime.datetime.now()
with open('Orders_File.csv', 'a') as orders:
orders = csv.writer(orders, delimiter=',')
orders.writerow([name, ID, credit_card, credit_digits, order.get_description(), time_of_order])
if __name__ == '__main__':
main()