-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOrdering foods with classes.py
More file actions
50 lines (34 loc) · 1.29 KB
/
Ordering foods with classes.py
File metadata and controls
50 lines (34 loc) · 1.29 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
from menu_item import MenuItem
menu_item1 = MenuItem('Sandwich', 5)
menu_item2 = MenuItem('Chocolate Cake', 4)
menu_item3 = MenuItem('Coffee', 3)
menu_item4 = MenuItem('Orange Juice', 2)
menu_items = [menu_item1, menu_item2, menu_item3, menu_item4]
index = 0
for menu_item in menu_items:
print(str(index) + '. ' + menu_item.info())
index += 1
print('--------------------')
order = int(input('Enter menu item number: '))
selected_menu = menu_items[order]
print('Selected item: ' + selected_menu.name)
# Receive input from the console and set the count variable to it
count = int(input('Enter quantity (10% off for 3 or more): '))
# Call the get_total_price method
result = selected_menu.get_total_price(count)
# Output 'Your total is $____'
print('Your total is $' + str(result))
//modules - menu_item.py
class MenuItem:
def __init__(self, name, price):
self.name = name
self.price = price
def info(self):
return self.name + ': $' + str(self.price)
def get_total_price(self, count):
total_price = self.price * count
# If count is 3 or higher, multiply it by 0.9
if count >= 3:
total_price *= 0.9
return round(total_price)
# Round total_price to the nearest whole number and return it