-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlab4.py
127 lines (115 loc) · 3.69 KB
/
lab4.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
# No Imports are required for this program
def main():
"""
Main function to run the Restaurant Receipt Generator.
"""
orders = get_orders()
menu = get_menu()
display_open_orders(orders)
order_number = get_order_number()
order = orders.get(order_number, [])
total, tax = generate_receipt(order, menu)
tip_percentage = display_tip_options(total, tax)
calculate_total_bill(total, tax, tip_percentage)
def get_orders():
"""
Returns a dictionary of hardcoded orders.
Key: Order number
Value: List of menu items
"""
return {
1: ['burger', 'fries', 'soda', 'apple pie'],
2: ['pizza', 'salad', 'breadsticks', 'water'],
3: ['pasta', 'garlic bread', 'wine', 'cheesecake'],
4: ['steak', 'mashed potatoes', 'green beans', 'ice cream'],
5: ['chicken sandwich', 'coleslaw', 'lemonade', 'brownie']
}
def get_menu():
"""
Returns a dictionary of hardcoded menu items and their prices.
Key: Menu item
Value: Price
"""
return {
'burger': 5.99,
'fries': 2.99,
'soda': 1.50,
'apple pie': 3.99,
'pizza': 8.99,
'salad': 4.99,
'breadsticks': 3.99,
'water': 0.00,
'pasta': 7.99,
'garlic bread': 2.99,
'wine': 6.99,
'cheesecake': 4.99,
'steak': 14.99,
'mashed potatoes': 3.99,
'green beans': 2.99,
'ice cream': 3.50,
'chicken sandwich': 6.99,
'coleslaw': 2.50,
'lemonade': 1.99,
'brownie': 2.99
}
def display_open_orders(orders):
"""
Displays the list of open orders.
"""
print("Open Orders:")
print("1")
print("2")
print("3")
print("4")
print("5")
def get_order_number():
"""
Prompts the user to enter an order number and returns it.
"""
return int(input("Which order would you like to generate a receipt for? "))
def generate_receipt(order, menu):
"""
Generates and prints the receipt for the given order.
"""
total = sum(map(menu.get, order))
print("\nReceipt:")
if len(order) > 0:
print(f"{order[0]}: ${menu[order[0]]:.2f}")
if len(order) > 1:
print(f"{order[1]}: ${menu[order[1]]:.2f}")
if len(order) > 2:
print(f"{order[2]}: ${menu[order[2]]:.2f}")
if len(order) > 3:
print(f"{order[3]}: ${menu[order[3]]:.2f}")
tax = total * 0.05
print(f"Total: ${total:.2f}")
print(f"Tax (5%): ${tax:.2f}")
return total, tax
def display_tip_options(total, tax):
"""
Displays the tip options and returns the selected tip percentage.
"""
tip_percentages = {"a": 0.15, "b": 0.20, "c": 0.25}
print("\nTip options:")
# Manually print each tip option
tip_amount_a = total * tip_percentages["a"]
final_total_a = total + tax + tip_amount_a
print(f"a) 15%: ${tip_amount_a:.2f} (Total: ${final_total_a:.2f})")
tip_amount_b = total * tip_percentages["b"]
final_total_b = total + tax + tip_amount_b
print(f"b) 20%: ${tip_amount_b:.2f} (Total: ${final_total_b:.2f})")
tip_amount_c = total * tip_percentages["c"]
final_total_c = total + tax + tip_amount_c
print(f"c) 25%: ${tip_amount_c:.2f} (Total: ${final_total_c:.2f})")
tip_choice = input("Choose a tip option (a, b, c): ")
return tip_percentages.get(tip_choice, 0)
def calculate_total_bill(total, tax, tip_percentage):
"""
Calculates and prints the total bill amount.
"""
total_bill = total + tax + (total * tip_percentage)
print(f"Selected tip percentage: {int(tip_percentage*100)}%")
print(f"Total bill: ${total_bill:.2f}")
print("Thank you for dining with Python Gourmet!")
if __name__ == "__main__":
main()