Knowee
Questions
Features
Study Tools

Write a program that helps users analyze the nutritional content of different foods. The program should prompt the user to enter the number of calories, protein grams, carbohydrate grams, fat grams, and fiber grams in a food item. Based on this information, the program should calculate and display the following:·       The percentage of calories that come from protein.·       The percentage of calories that come from carbohydrates.·       The percentage of calories that come from fat.·       The percentage of calories that come from fiber. Additionally, the program should determine the level of fat in the food item and display it as "low", "moderate", or "high" based on the percentage of calories from fat: ·       If the percentage of calories from fat is less than 30%, the food is considered low in fat.·       If the percentage of calories from fat is between 30% and 60%, the food is considered moderate in fat.·       If the percentage of calories from fat is greater than 60%, the food is considered high in fat.Ensure that the program handles input validation to prevent negative values for any of the nutritional components.Input:·       Number of calories in the food (an integer)·       Number of protein grams in the food (an integer)·       Number of carbohydrate grams in the food (an integer)·       Number of fat grams in the food (an integer)·       Number of fiber grams in the food (an integer)Output:·       Percentage of calories from protein (a floating-point number)·       Percentage of calories from carbohydrates (a floating-point number)·       Percentage of calories from fat (a floating-point number)·       Percentage of calories from fiber (a floating-point number)·       Level of fat in the food (a string: "low", "moderate", or "high")Constraints:·       All input values are non-negative integers.·       Each input value should fit within the range of an integer data type.

Question

Write a program that helps users analyze the nutritional content of different foods. The program should prompt the user to enter the number of calories, protein grams, carbohydrate grams, fat grams, and fiber grams in a food item. Based on this information, the program should calculate and display the following:·       The percentage of calories that come from protein.·       The percentage of calories that come from carbohydrates.·       The percentage of calories that come from fat.·       The percentage of calories that come from fiber. Additionally, the program should determine the level of fat in the food item and display it as "low", "moderate", or "high" based on the percentage of calories from fat: ·       If the percentage of calories from fat is less than 30%, the food is considered low in fat.·       If the percentage of calories from fat is between 30% and 60%, the food is considered moderate in fat.·       If the percentage of calories from fat is greater than 60%, the food is considered high in fat.Ensure that the program handles input validation to prevent negative values for any of the nutritional components.Input:·       Number of calories in the food (an integer)·       Number of protein grams in the food (an integer)·       Number of carbohydrate grams in the food (an integer)·       Number of fat grams in the food (an integer)·       Number of fiber grams in the food (an integer)Output:·       Percentage of calories from protein (a floating-point number)·       Percentage of calories from carbohydrates (a floating-point number)·       Percentage of calories from fat (a floating-point number)·       Percentage of calories from fiber (a floating-point number)·       Level of fat in the food (a string: "low", "moderate", or "high")Constraints:·       All input values are non-negative integers.·       Each input value should fit within the range of an integer data type.

...expand
🧐 Not the exact question you are looking for?Go ask a question

Solution

Here is a Python program that fulfills the requirements:

def food_analysis():
    # Get user input
    calories = int(input("Enter the number of calories: "))
    protein = int(input("Enter the number of protein grams: "))
    carbs = int(input("Enter the number of carbohydrate grams: "))
    fat = int(input("Enter the number of fat grams: "))
    fiber = int(input("Enter the number of fiber grams: "))

    # Ensure all inputs are non-negative
    if any(x < 0 for x in [calories, protein, carbs, fat, fiber]):
        print("Error: All input values must be non-negative.")
        return

    # Calculate percentages
    protein_cal = protein * 4
    carbs_cal = carbs * 4
    fat_cal = fat * 9
    fiber_cal = fiber * 4

    protein_perc = (protein_cal / calories) * 100
    carbs_perc = (carbs_cal / calories) * 100
    fat_perc = (fat_cal / calories) * 100
    fiber_perc = (fiber_cal / calories) * 100

    # Determine fat level
    if fat_perc < 30:
        fat_level = "low"
    elif fat_perc <= 60:
        fat_level = "moderate"
    else:
        fat_level = "high"

    # Print results
    print("Percentage of calories from protein: ", protein_perc)
    print("Percentage of calories from carbohydrates: ", carbs_perc)
    print("Percentage of calories from fat: ", fat_perc)
    print("Percentage of calories from fiber: ", fiber_perc)
    print("Level of fat in the food: ", fat_level)

food_analysis()

This program first prompts the user to enter the nutritional information. It then checks that all inputs are non-negative. If they are, it calculates the percentage of calories that come from each nutrient and determines the fat level of the food. Finally, it prints the results.

This problem has been solved

Similar Questions

Educators are required to know how to read food labels and identify various ingredients and additives.What are the recommended totals of fat, sugars, and sodium based on the Eat for Health nutritional label breakdown

Develop a Java program to assist a user in managing their daily calorieintake. Allow the user to input the calories consumed for breakfast, lunch,and dinner. Use control statements to calculate the total calories consumedthroughout the day. Implement operators to perform arithmetic calculationsto determine the total calories. Display the total calorie count to the userand provide feedback on whether they have exceeded or stayed within theirdaily calorie limit (e.g., 2000 calories). Utilize appropriate data types,operators, and control statements to help users track and manage their dailycalorie intake effectively.

. What is a measure of the energy you get from food?A.FiberB.CalorieC.Trans-FatD.Carbohydrate

A nutritionist need to study the daily protein intake of a client (during 3 week period), present in different food items and the data collected by him is as follows:32, 21, 12, 43, 16, 48, 56, 24, 40, 45, 34, 11, 43, 33, 25, 34, 55, 32, 22, 20, 42

Uma embalagem de biscoito apresenta as informações nutricionais reproduzidas a seguir. Informação Nutricional Porção 30g (7 unidades) Valor energético 136kcal Carboidratos (não açúcares) 22g Carboidratos (açúcares) 20g Proteínas 2,0g Gorduras totais 4,4g Fibra alimentar 1,1g Sódio 147mg Marcos está em uma rigorosa dieta em que só pode consumir, no máximo, 1.500kcal por dia. Além disso, a dieta só permite o consumo diário de, no máximo, 400g de carboidratos, sendo esses açúcares ou não açúcares. Em especial, no que se refere aos açúcares, a dieta de Marcos restringe-o ao consumo máximo diário de 120g. Para seguir a dieta, Marcos pode consumir, em um dia, uma quantidade máxima de biscoito, em unidades, igual a A)9. B)11. C)42. D)66. E)77.

1/2

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.