I need help fixing this python code so that it can display the output like shown below class FoodItem:     def __init__(self):         self.name = "Water"         self.fat = 0.00         self.carbs = 0.00         self.protein = 0.00     def foodItem(self,name,fat,carbs,protein,servings):         print(f"\nNutritional information per serving of {name}:")         if name == self.name:             print("Enter food name: Enter fat:")         else:             print(f'Fat: {fat}g')             print(f'Carbohydrates: {carbs}g')             print(f'Protein: {protein}g')             calories = fat*9 + carbs*4 + protein*4             print(f'Number of calories for 1.00 serving(s): {calories}')             print(f'Number of calories for {servings} serving(s): {servings*calories}') if __name__ == '__main__':     name = input("Enter food name: ")     fat = float(input("Enter fat: "))     carbs = float(input("Enter carbs: "))     protein = float(input("Enter protein: "))     servings = float(input("Enter number of servings: "))     food = FoodItem()     food.foodItem(name,fat,carbs,protein,servings)

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter6: Modularity Using Functions
Section: Chapter Questions
Problem 9PP
icon
Related questions
Question

I need help fixing this python code so that it can display the output like shown below

class FoodItem:
    def __init__(self):

        self.name = "Water"
        self.fat = 0.00
        self.carbs = 0.00
        self.protein = 0.00

    def foodItem(self,name,fat,carbs,protein,servings):
        print(f"\nNutritional information per serving of {name}:")

        if name == self.name:
            print("Enter food name: Enter fat:")

        else:
            print(f'Fat: {fat}g')
            print(f'Carbohydrates: {carbs}g')
            print(f'Protein: {protein}g')
            calories = fat*9 + carbs*4 + protein*4
            print(f'Number of calories for 1.00 serving(s): {calories}')
            print(f'Number of calories for {servings} serving(s): {servings*calories}')

if __name__ == '__main__':

    name = input("Enter food name: ")
    fat = float(input("Enter fat: "))
    carbs = float(input("Enter carbs: "))
    protein = float(input("Enter protein: "))
    servings = float(input("Enter number of servings: "))

    food = FoodItem()

    food.foodItem(name,fat,carbs,protein,servings)

Input Water
Your output
Expected output
mpare output
Input
Your output
Enter food name: Enter fat:
Output differs. See highlights below. Special character legend
Expected output
Nutritional information per serving of Water:
Fat: 0.00 gel
Carbohydrates: 0.00 ge
Protein: 0.00 gel
Number of calories for 1.00 serving (s): 0.004
M&M's
10.0
34.0
2.0
3.0
Enter food name: Enter fat: Enter carbs: Enter protein: Enter number
Nutritional information per serving of M&M's:
Fat: 10.0g
Carbohydrates: 34.0g
Protein: 2.0g
Number of calories for 1.00 serving (s): 234.0
Number of calories for 3.0 serving (s): 702.0
Nutritional information per serving of M&M's:
Fat: 10.00 g
Carbohydrates: 34.00 g
Protein: 2.00 g
Number of calories for 1.00 serving (s): 234.00
Number of calories for 3.00 serving (s): 702.00
Transcribed Image Text:Input Water Your output Expected output mpare output Input Your output Enter food name: Enter fat: Output differs. See highlights below. Special character legend Expected output Nutritional information per serving of Water: Fat: 0.00 gel Carbohydrates: 0.00 ge Protein: 0.00 gel Number of calories for 1.00 serving (s): 0.004 M&M's 10.0 34.0 2.0 3.0 Enter food name: Enter fat: Enter carbs: Enter protein: Enter number Nutritional information per serving of M&M's: Fat: 10.0g Carbohydrates: 34.0g Protein: 2.0g Number of calories for 1.00 serving (s): 234.0 Number of calories for 3.0 serving (s): 702.0 Nutritional information per serving of M&M's: Fat: 10.00 g Carbohydrates: 34.00 g Protein: 2.00 g Number of calories for 1.00 serving (s): 234.00 Number of calories for 3.00 serving (s): 702.00
Expert Solution
steps

Step by step

Solved in 3 steps with 3 images

Blurred answer
Knowledge Booster
Types of Loop
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr