-
Notifications
You must be signed in to change notification settings - Fork 466
Expand file tree
/
Copy pathpizza-Order.py
More file actions
178 lines (153 loc) · 5.36 KB
/
pizza-Order.py
File metadata and controls
178 lines (153 loc) · 5.36 KB
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
'''
# Pizza Order Program
Entites :
1) Pizza attributes (size, base_price,collection toppings)
2) Toppings attributes (name, price)
3) Order attributes (pizzas, total_price, discount,status('pending','completed','cancelled') , customer_id)
4) Customer attributes (name, phone_number, email, address) (future extend )
5) Payment attributes (order_id, amount, payment_method('cash','card','online'), payment_status('pending','completed','failed')) (future extend )
6) Menu attributes (pizzas, toppings, prices)
MENU = {
'pizzas': {
'base_price': 13.00,
'sizes': {
'small': {'price_modifier': -2.00, 'diameter': 10},
'medium': {'price_modifier': 0.00, 'diameter': 12},
'large': {'price_modifier': 2.00, 'diameter': 14}
}
},
'toppings': {
'pepperoni': 1.00,
'mushroom': 0.50,
'olive': 0.50,
'anchovy': 2.00,
'ham': 1.50,
'extra_cheese': 1.00
},
'drinks': {
'small': 2.00,
'medium': 3.00,
'large': 3.50
},
'wings': {
10: 5.00,
20: 9.00,
40: 17.50
}
}
Application Flow:
1) Welcome and Menu Display
2) Pizza Selection and customization
3) Additional Items (Drinks and Wings)
4) Order Summary and Confirmation
5) Payment Processing
'''
MENU = {
'pizza_sizes': {
'small': {'price_modifier': -2.00, 'diameter': 10},
'medium': {'price_modifier': 0.00, 'diameter': 12},
'large': {'price_modifier': 2.00, 'diameter': 14}
},
'pizzas': {
'margherita': {'base_price': 12.00},
'pepperoni': {'base_price': 14.00},
'veggie_supreme': {'base_price': 13.50}
},
'toppings': {
'pepperoni': 1.00,
'mushroom': 0.50,
'olive': 0.50,
'anchovy': 2.00,
'ham': 1.50,
'extra_cheese': 1.00
},
'drinks': {
'small': 2.00,
'medium': 3.00,
'large': 3.50
},
'wings': {
10: 5.00,
20: 9.00,
40: 17.50
}
}
class Pizza:
def __init__(self,name='margherita',size='medium'):
self.name = name
self.size = size
self.toppings = []
self.order_items = []
self.total_cost = 0.0
@staticmethod
def display_menu():
print("\n🍕 Welcome to Python Pizza 🍕\n")
print("--------- PIZZAS ---------")
for pizza_name, pizza_data in MENU['pizzas'].items():
print(f"\n{pizza_name.replace('_',' ').title()}:")
base = pizza_data['base_price']
for size, info in MENU['pizza_sizes'].items():
price = base + info['price_modifier']
print(f" {size.title():<10} ({info['diameter']}”): ${price:.2f}")
print("\n---- TOPPINGS ----")
for topping, price in MENU['toppings'].items():
print(f"{topping.replace('_', ' ').title():<15} ${price:.2f}")
print("\n---- DRINKS ----")
for size, price in MENU['drinks'].items():
print(f"{size.title():<10} ${price:.2f}")
print("\n---- WINGS ----")
for qty, price in MENU['wings'].items():
print(f"{str(qty)+' pcs':<10} ${price:.2f}")
print("\n--------------------------")
print("⭐ Choose your pizza, size, and toppings")
print("⭐ Add drinks & wings for a combo deal\n")
def choose_pizza(self):
while True:
choice = input("Choose a pizza (margherita, pepperoni, veggie_supreme): ").strip().lower()
if choice in MENU['pizzas']:
self.name = choice
base_price= MENU['pizzas'][choice]['base_price']
self.total_cost += base_price
self.order_items.append((choice, base_price))
break
else:
print("Invalid choice. Please try again.")
def choose_size(self):
while True:
size = input("Choose a size (small, medium, large): ").strip().lower()
if size in MENU['pizza_sizes']:
self.size = size
size_modifier = MENU['pizza_sizes'][size]['price_modifier']
self.total_cost += size_modifier
self.order_items.append((size, size_modifier))
break
else:
print("Invalid size. Please try again.")
def choose_toppings(self):
while True:
topping = input("Add a topping (type 'done' when finished): ").strip().lower()
if topping == 'done':
break
elif topping in MENU['toppings']:
price = MENU['toppings'][topping]
self.total_cost += price
self.toppings.append(topping)
self.order_items.append((topping, price))
else:
print("Invalid topping. Please try again.")
def calculateBill(self):
print("\n --- ORDER SUMMARY ---")
for item ,price in self.order_items:
print(f"{item.replace('_',' ').title():<20} ${price:.2f}")
print("-"*35)
print(f"\nTotal Cost: ${self.total_cost:.2f}")
def order(self):
print("WELCOME TO PYTHON PIZZA!")
print("Here's our menu:")
self.display_menu()
self.choose_pizza()
self.choose_size()
self.choose_toppings()
self.calculateBill()
p1 = Pizza()
p1.order()