08 Apr Tuesday 7:30 Python Practice – 22.04.05.
Question:
Create a class called Food. The class should contain three class attributes, the name of the food(string), the sugar(int or float), and the fat(int or float) content.
The tastiness of a particular food is based on the amount of sugar + fat that food has. So we
will need a class function to calculate the tastiness.
Now onto the static members in our class, we should have a static variable called all_foods. This
will be a list and whenever a new food is instantiated (created), that new food will get added to this list.
Finally, create a static function called get_tastiest that returns the tastiest food from all_foods.
Make sure that all_foods is storing the entire Food object and not just the name as a string!
Sorry, the comment form is closed at this time.