In: Computer Science
use python3 language and need answer ASAP please thank you.
The primary sources of calories in food are fat, carbohydrate, and protein. Proteins and carbohydrates have four calories per gram, and fat has nine calories per gram.
For example, on a box of Honey Nut Cheerios, it says that a serving has 1.5 grams of fat, 22 grams of carbohydrates, and 2 grams of protein. That works out to:
1.5 * 9 + 22 * 4 + 2 * 4 = 109.5
And right there on the box it says that one serving has 110 calories. create a CGI program to compute calories. You need to write a CGI program which can accept the data from the form and print out a report of the calories. The field names your CGI must accept are: food, for the name of the food; carbs, for the amount of carbohydrates; protein, for the amount of protein; and fats, for the amount of fat.
And here are the correct values for some foods you can try your program out on. (These are rounded to integers, but you don't need to do that.)
Honey Nut Cheerios: fat grams: 1.5 carb grams: 22 protein grams: 2 total calories: 110 Big Mac: fat grams: 29 carb grams: 46 protein grams: 25 total calories: 545 banana: fat grams: 0.4 carb grams: 27 protein grams: 1.3 total calories: 117 potato: fat grams: 0.2 carb grams: 37 protein grams: 4.3 total calories: 167
food = input("Enter food name: ") #reading the inputs from the
user
fat = float(input("Enter amount of fat: "))
carb = float(input("Enter amount of carbohydrates: "))
protein = float(input("Enter amount of protein: "))
calories = fat*9+carb*4+protein*4 #calculating the number of
calories
print(f"{food}:\nfat grams: {fat}\ncarb grams: {carb}\nprotein
grams: {protein}\ntotal calories: {calories}") #printing the
result