NOTE : Is learning \"Python programming\" (currently on chapter 5) with the foll
ID: 3871766 • Letter: N
Question
NOTE: Is learning "Python programming" (currently on chapter 5) with the following textbook:
Book "Starting Out With Python" 3rd Edition by Gaddis
2. 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. Then, she calculates the number of calories that result from the fat, using the following formula: calories from fat = fat grams * 9 Next, she calculates the number of calories that result from the carbohydrates, using the following formula: calories from carbs - carb grams * 4 The nutritionist asks you to write a program that will make these calculations. Use a function that will allow you to display both calculations (by passing in the number of grams and the number of calories per gram) /workspace/HH/ $ python numbero Enter number of fat grams you ate today: 10 Enter number of carb grams you ate today: 20 10 grams have 90 calories 20 grams have 80 caloriesExplanation / Answer
# taking user input
# input method returns a string, so converting it to integer
fat = int(input("Enter number of fat grams you you ate today: "))
carb = int(input("Enter number of carb grams you ate today: "))
# printing output
print(fat, "grams have",fat*9,"calories")
print(carb, "grams have",carb*4,"calories")
Sample Output
# taking user input
# input method returns a string, so converting it to integer
fat = int(input("Enter number of fat grams you you ate today: "))
carb = int(input("Enter number of carb grams you ate today: "))
# printing output
print(fat, "grams have",fat*9,"calories")
print(carb, "grams have",carb*4,"calories")
Sample Output
Enter number of fat grams you you ate today: 10 Enter number of carb grams you ate today: 20 10 grams have 90 calories 20 grams have 80 calories
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.