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)

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
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
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education