File tree Expand file tree Collapse file tree 4 files changed +43
-0
lines changed
Expand file tree Collapse file tree 4 files changed +43
-0
lines changed Original file line number Diff line number Diff line change 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)'
Original file line number Diff line number Diff line change 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 ))
Original file line number Diff line number Diff line change 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 )
Original file line number Diff line number Diff line change 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 ())
You can’t perform that action at this time.
0 commit comments