|
| 1 | +class MenuItem: |
| 2 | + def __init__(self, name, price): |
| 3 | + self.name = name |
| 4 | + self.price = price |
| 5 | + |
| 6 | + def info(self): |
| 7 | + return self.name + ': $' + str(self.price) |
| 8 | + |
| 9 | + def get_total_price(self, count): |
| 10 | + total_price = self.price * count |
| 11 | + |
| 12 | + if count >= 3: |
| 13 | + total_price *= 0.9 |
| 14 | + |
| 15 | + return round(total_price) |
| 16 | + |
| 17 | +class Food(MenuItem): |
| 18 | + def __init__(self, name, price, calorie_count): |
| 19 | + super().__init__(name, price) |
| 20 | + self.calorie_count = calorie_count |
| 21 | + |
| 22 | + def info(self): |
| 23 | + return self.name + ': $' + str(self.price) + ' (' + str(self.calorie_count) + 'kcal)' |
| 24 | + |
| 25 | + def calorie_info(self): |
| 26 | + print('kcal: ' + str(self.calorie_count)) |
| 27 | + |
| 28 | +class Drink(MenuItem): |
| 29 | + def __init__(self, name, price, volume): |
| 30 | + super().__init__(name, price) |
| 31 | + self.volume = volume |
| 32 | + |
| 33 | + def info(self): |
| 34 | + return self.name + ': $' + str(self.price) + ' (' + str(self.volume) + 'mL)' |
| 35 | + |
| 36 | + |
| 37 | + |
| 38 | +food1 = Food('Sandwich', 5, 330) |
| 39 | +food2 = Food('Chocolate Cake', 4, 450) |
| 40 | +food3 = Food('Cream Puff', 2, 180) |
| 41 | + |
| 42 | +foods = [food1, food2, food3] |
| 43 | + |
| 44 | +drink1 = Drink('Coffee', 3, 180) |
| 45 | +drink2 = Drink('Orange Juice', 2, 350) |
| 46 | +drink3 = Drink('Espresso', 3, 30) |
| 47 | + |
| 48 | +drinks = [drink1, drink2, drink3] |
| 49 | + |
| 50 | +print('Food') |
| 51 | +index = 0 |
| 52 | +for food in foods: |
| 53 | + print(str(index) + '. ' + food.info()) |
| 54 | + index += 1 |
| 55 | + |
| 56 | +print('Drinks') |
| 57 | +index = 0 |
| 58 | +for drink in drinks: |
| 59 | + print(str(index) + '. ' + drink.info()) |
| 60 | + index += 1 |
| 61 | + |
| 62 | +print('--------------------') |
| 63 | + |
| 64 | +food_order = int(input('Enter food item number: ')) |
| 65 | +selected_food = foods[food_order] |
| 66 | + |
| 67 | +drink_order = int(input('Enter drink item number: ')) |
| 68 | +selected_drink = drinks[drink_order] |
| 69 | + |
| 70 | +# Take input from the console and assign it to the count variable |
| 71 | +count = int(input('How many meals would you like to purchase? (10% off for 3 or more): ')) |
| 72 | + |
| 73 | +# Call the get_total_price method from selected_food and from selected_drink |
| 74 | +result = selected_food.get_total_price(count) + selected_drink.get_total_price(count) |
| 75 | + |
| 76 | +# Output 'Your total is $____' |
| 77 | +print('Your total is $ ' + str(result)) |
| 78 | +print('Happy to help you!!!') |
| 79 | +print('Made by ASHANK') |
0 commit comments