# complete the fooditem class by adding a constructor to initalize a food item. The constructor should initailize the name (a string)
# To water and all other instance attributes to 0.0 by default
#If the constructor is called with a food name, grams of fat, grams of carbohydrates and grams of protein, the constructor should assign each instance
# attribute with the appropriate parameter value.
class FoodItem:
#Constructor with defaults
def__init__(self, name="Water", fat=0.0, carbs=0.0, protein=0.0):
self.name = name
self.fat = float(fat)
self.carbs = float(carbs)
self.protein = float(protein)
def get_calories(self, num_servings):
# calories per serving
calories_per_serving = (self.fat * 9) + (self.carbs * 4) + (self.protein * 4)
return calories_per_serving * num_servings
def print_info(self):
print(f'Nutritional information per serving of {self.name}:')
print(f' Fat: {self.fat:.2f} g')
print(f' Carbohydrates: {self.carbs:.2f} g')
print(f' Protein: {self.protein:.2f} g')
if__name == "__main__":
item_name = input()
if item_name == 'Water' or item_name == 'water':
#Uses constructor defaults
food_item = FoodItem()
food_item.print_info()
print(f 'Number of calories for {1.0:.2f} servings(s): {food_itme.get_calories(1.0):.2f}')
else:
amount_fat = float(input())
amount_carbs = float(input())
amount_protein = float(input())
num_servings = float(input())
food_item = FoodItem(item_name, amount_fat, amount_carbs, amount_protein)
food_item.print_info()
print(f'Number of calories for {1.0:.2f} serving(s): {food_item.get_calories(1.0):.2f}')
print(f'Number of calories for {num_servings:.2f} serving(s): {food_item.get_calories(num_servings):.2f}')
To embed this project on your website, copy the following code and paste it into your website's HTML: