Skip to content

Commit d591844

Browse files
Add files via upload
1 parent fac7c11 commit d591844

File tree

4 files changed

+43
-0
lines changed

4 files changed

+43
-0
lines changed

python_study_5/page8/drink.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from menu_item import MenuItem
2+
3+
class Drink(MenuItem):
4+
def info(self):
5+
return self.name + ': $' + str(self.price) + ' (' + str(self.volume) + 'mL)'

python_study_5/page8/food.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from menu_item import MenuItem
2+
3+
class Food(MenuItem):
4+
def __init__(self, name, price, calorie_count):
5+
# Using super() call __init__() from the parent class
6+
super().__init__(name, price)
7+
8+
self.calorie_count = calorie_count
9+
10+
def info(self):
11+
return self.name + ': $' + str(self.price) + ' (' + str(self.calorie_count) + 'kcal)'
12+
13+
def calorie_info(self):
14+
print('kcal: ' + str(self.calorie_count))

python_study_5/page8/menu_item.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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)

python_study_5/page8/script.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from food import Food
2+
from drink import Drink
3+
4+
food1 = Food('Sandwich', 5, 330)
5+
print(food1.info())
6+
7+
drink1 = Drink('Coffee', 3)
8+
drink1.volume = 180
9+
print(drink1.info())

0 commit comments

Comments
 (0)