-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPass 5
More file actions
111 lines (93 loc) · 3.3 KB
/
Copy pathPass 5
File metadata and controls
111 lines (93 loc) · 3.3 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
# python-challenge-1
# UNC AI Bootcamp Week 2 Homework Assignment
# Food Truck Ordering System
# Menu
menu = {
"Snacks": {"Cookie": 0.99, "Banana": 0.69, "Apple": 0.49, "Granola bar": 1.99},
"Meals": {"Burrito": 4.49, "Teriyaki Chicken": 9.99, "Sushi": 7.49, "Pad Thai": 6.99},
"Drinks": {"Soda": 1.99, "Tea": 2.49, "Coffee": 2.99},
"Desserts": {"Chocolate cake": 3.49, "Ice cream": 2.99}
}
# Welcome Customer
customer_name = input("Welcome to John's Food Truck! What's your name? ")
print(f"Hi, {customer_name}! Here's our menu:")
# Order List
order_list = []
# Present Menu
def present_menu():
menu_title = "John's Food Truck Menu"
print("\n" + "=" * 40)
print(f"{menu_title.center(40)}")
print("=" * 40)
for category, items in menu.items():
print(f"\n-- {category} --".center(40))
for item, price in items.items():
print(f"{item.ljust(30, '.')} ${price:>.2f}")
print("=" * 40 + "\n")
# Customer Category Selection
def customer_selection():
present_menu()
category = input("Please choose a category (Snacks, Meals, Drinks, Desserts) or type 'exit' to finish: ").title()
if category in menu:
return category
elif category.lower() == 'exit':
return None
else:
print("Invalid category. Please try again.")
return customer_selection()
# Order Items
def order_items(category):
print(f"\n{category} options:")
for idx, (item, price) in enumerate(menu[category].items(), 1):
print(f"{idx}. {item}: ${price:.2f}")
while True:
try:
item_choice = int(input("Choose an item by number: "))
if 1 <= item_choice <= len(menu[category]):
item_name = list(menu[category].keys())[item_choice - 1]
item_price = menu[category][item_name]
quantity = input(f"How many {item_name}'s? (default 1): ")
quantity = int(quantity) if quantity.isdigit() else 1
order_list.append({"Item name": item_name, "Price": item_price, "Quantity": quantity})
break
else:
print("Invalid selection. Please try again.")
except ValueError:
print("Please enter a number.")
# Match-case for customer's decision
def customer_decision():
decision = input("Would you like to order something else? (Y/N): ").lower()
match decision:
case 'y':
return True
case 'n':
return False
case _:
print("Invalid input. Please type 'Y' for yes or 'N' for no.")
return customer_decision()
# Order Receipt
def print_receipt():
print("\nYour order receipt:")
print()
print("Items".ljust(24) + "| Price | Quantity")
print("-" * 40)
total = 0
for item in order_list:
item_name, price, quantity = item["Item name"], item["Price"], item["Quantity"]
total += price * quantity
name_spaces = " " * (24 - len(item_name))
print(f"{item_name}{name_spaces}| ${price:.2f} | {quantity}")
print(f"\nTotal: ${total:.2f}")
print()
# Main
while True:
category = customer_selection()
if not category:
break
order_items(category)
if not customer_decision():
break
print_receipt()
print()
print("Thank you for your order!")
# Note ChatGPT Code refactoring for