-
-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathfood_class.py
More file actions
34 lines (30 loc) · 1.03 KB
/
food_class.py
File metadata and controls
34 lines (30 loc) · 1.03 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
"""
Food
Create a Food class with 4 instance
attributes: name. calories, grams of
protein, and grams of fat.
It should have 2 methods: an eat method
that prints "You are eating " and the name
of the food, and a burn method that prints
"You burned [x] calories." where [x] is
the number of calories in the food.
Create a JunkFood subclass and a Meal
subclass. Both subclasses should carry
over the attributes and methods of the
Food class.
The JunkFood subclass should have an
additional attribute for the grams of
sugar contained in the food, and the Meal
subclass should have an additional attribute
for the mg of sodium it contains.
Create a list called snacks and fill it with at
least 3 junk foods, and create a list called
meals and fill it with at least 3 meals.
Then, use Python to show that you ate all the
foods in both lists, and burned off one meal
(pick this meal randomly).
Display the total number of calories,
grams of protein, grams of fat, grams of
sugar, and mg of sodium that you ate (the total
for all the foods in both lists).
"""