Question

Write a Python program that asks the user to enter the number of calories and fat...

Write a Python program that asks the user to enter the number of calories and fat grams in a food item. The program should display the percentage of the calories that come from fat. One gram of fat has 9 calories,

therefore:

Calories from fat = fat grams * 9

The percentage of calories from fat can be calculated as follows:

Calories from fat / total calories

If the calories from fat are less than 30 percent of the total calories of the food, it should also display a message indicating the food is low in fat.

Note: The number of calories from fat cannot be greater than the total number of calories in the food item. If the program determines that the number of calories from fat is greater than the number of calories in the food item, it should display an error message indicating the input is invalid

0 0
Add a comment Improve this question Transcribed image text
Answer #1
#CalcPercent.py
cals = float(input("Enter the number of calories: "))
fat = float(input("Enter the number of fat grams: "))
total = cals + 9*fat
percent = ((9*fat)/total) * 100
print("Percentage of the calories that come from fat =",percent)
if(percent<30):
    print("Food is low in fat")
Add a comment
Know the answer?
Add Answer to:
Write a Python program that asks the user to enter the number of calories and fat...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Design a program that asks for the number of fat grams and calories in a food...

    Design a program that asks for the number of fat grams and calories in a food item. Validate the input as follows: Make sure the number of grams and calories is not less than 0. According to nutritionist formulas, the number of calories cannot exceed fat grams x 9. Make sure that the number of calories entered is not greater than fat grams x 9. Once correct data has been entered, the program should calculate and display the percentage of...

  • In Python code: Write a program to calculate the percentage of fat calories in a food...

    In Python code: Write a program to calculate the percentage of fat calories in a food item. Your program should allow the total number of calories in the food item and the number of grams of fat. Validate the input as follows: - Make sure the number of calories and the number of fat grams are not less than 0. - There are 9 calories in every gram of fat. The calories from fat must not exceed the total calories...

  • 1. Creatc a lava program thal asks the user to cnter his/her first name and last...

    1. Creatc a lava program thal asks the user to cnter his/her first name and last namc, in a single linc and separaled by a spacc. The program should output separately the first namc and the last name. (Use the Scanner class.) 2. Create a Java program thal asks the user for a medium (air, water or sleel), and outputs the speed of sound in thal medium (1 100 feclsec in air, 4900 feesec in water and 16,400 feet sec...

  • Python help. Write a program that asks the user to enter a person's age. The program...

    Python help. Write a program that asks the user to enter a person's age. The program should display a message indicating whether the person is an infant, a child, a teenager, or an adult. Following are the guidelines: If the person is 2 year old or less, he or she is an infant. If the person is older than 2 year, but younger than 13 years, he or she is a child. If the person is at least 13 years...

  • Write a program that asks the user to enter a number ofseconds.• There are...

    Starting Out with C++ (9th Edition)  Chapter 4, Problem 7PCWrite a program that asks the user to enter a number of seconds.• There are 86400 seconds in a day. If the number of seconds entered by the user is greater than or equal to 86400, the program should display the number of days in that many seconds.• There are 3600 seconds in an hour. If the number of seconds entered by the user is less than 86400, but is greater...

  • in python Write a Bonus Calculator for a company. Program asks user to enter sales in...

    in python Write a Bonus Calculator for a company. Program asks user to enter sales in a month separated by commas. Program asks years of experience • If salesperson have total sales greater than 200,000 dollars he/she will get 5% bonus between 100,000 and 200,000 dollars and greater than 10 years of experience he/she will get 4% bonus - between 100,000 and 200,000 dollars and less than 10 years of experience he/she will get 3% bonus • less than than...

  • Write a program that asks the user to enter a string and then asks the user...

    Write a program that asks the user to enter a string and then asks the user to enter a character. The program should count and display the number of times that the specified character appears in the string. python programming

  • Write a program that asks the user to input the number of males and females registered...

    Write a program that asks the user to input the number of males and females registered in a class (Max 30 members in the class). The program should display the percentage of males and females in the class. Python programming question

  • Python Programming 4th Edition: Write a program that asks the user for the number of feet....

    Python Programming 4th Edition: Write a program that asks the user for the number of feet. The program converts those feet to inches by using the formula ’12 * feet’. Hint: Define main () program Get the number of feet from the user Define variables Call a function feet_to_inches(feet) The function receives the number of feet and returns the number of inches in that many feet. The output should look like as follows: Enter the number of feet: If the...

  • Write a java program that asks the user to enter an integer. The program should then...

    Write a java program that asks the user to enter an integer. The program should then print all squares less than the number entered by the user. For example, if the user enters 120, the program should display 0, 1, 4, 9, 16, 25, 36, 49, 64, 81, and 100.

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT