Question: Write a Python program that uses function(s) for the following problem: 81 81 Activity7: Calories from Fat and Carbohydrates At What to do: Write a

Write a Python program that uses function(s) for the following problem:

Write a Python program that uses function(s) for the following problem: 81

81 81 Activity7: Calories from Fat and Carbohydrates At What to do: Write a Python program that uses function(s) for the following problem: A nutritionist who works for a fitness club helps members by evaluating their diets. As part of her evaluation, she asks members for the number of fat grams and carbohydrate grams that they consumed in a day (two inputs, one for number of fat grams and the other for number of carb grams). Then, she calculates the number of calories that result from the fat, using the following formula: calories from fat = fat grams x 9 Next, she calculates the number of calories that result from the carbohydrates, using the following formula: calories from cabs = carb grams x 4 The nutritionist asks you to write a program that will make these calculations. Make sure that your program does not allow user to enter negative values for fat grams and carb grams (that is, validate the input with a loop). Note: you can write one function that takes as its parameters the number of grams and calories generated per gram respectively, and calculates and returns the total calories generated. You can call the function twice, once for fat grams and once for carb grams. For example, calculate_calories(30.5, 9) will return 274.5 calculate_calories(75.8, 4) will return 303.2

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!