1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
GarryVolchara [31]
3 years ago
9

Write a program that asks for the number of calories and fat grams in a food. The program should display the percentage of calor

ies that come from fat. If the calories from fat are less than 30% of the total calories of the food, it should also display a message indicating that the food is low in fat. One gram of fat has 9 calories, so Calories from fat = fat grams * 9 The percentage of calories from fat can be calculated as Calories from fat total calories Input Validation: Make sure the number of calories and fat grams are not less than 0. Also, the number of calories from fat cannot be greater than the total number of calories. If that happens, display an error message indicating that either the calories or fat grams were incorrectly entered.
Computers and Technology
1 answer:
Zigmanuir [339]3 years ago
7 0

Answer:

 The solution code is written in Python 3:

  1. calories = int(input("Enter number of calories: "))
  2. fats = int(input("Enter number of fat in grams: "))
  3. if(calories > 0 and fats > 0):
  4.    cf = fats * 9
  5.    if(cf < calories):
  6.        percent = cf / calories  
  7.        if(percent < 0.3):
  8.            print("Food is low in fat")
  9.    else:
  10.        print("Error input. Calories from fat cannot more than total calories")
  11. else:
  12.    print("Error input. Calories and fats must be more than 0")

Explanation:

Firstly, use input function to ask user to enter total number of calories and fat in grams (Line 1-2)

Next we do the first input validation to check if the calories and fats are more than 0 (Line 4). If so apply formula to calculate calories from fats. If not, print error input message (Line 5, 13)

Then we proceed to next input validation to check if calories from fact more than total calories. If so, proceed to calculate percentage of calories from fats and if it is lower than 30%, display the appropriate message (Line 6 - 9). If fail the second input validation, the program will display another error input message again (Line 11)

You might be interested in
All linear programming problems have all of the following properties EXCEPT
lyudmila [28]

Answer:

alternative optimal solutions

Explanation:

8 0
3 years ago
Read 2 more answers
Explain why the receptionist responded as indicated in the following scenario.
slavikrds [6]
The receptionist is aware of the every day attire as he works there. Jim and Roger are undressed, since they were wearing blue jeans. The receptionist lets them know of what’s expected.

Hope this helps!
4 0
1 year ago
What do you think about the use the top song on a video you are creating
stepladder [879]

Hiya!


Using a popular song in a video your making is most definitely going to attract more viewers. It's all about making the video appeal to the person.

^Hope this helps

3 0
2 years ago
Read 2 more answers
Which source would provide the best way to find valid information about climate change
igor_vitrenko [27]
Primary sources would be best
4 0
2 years ago
"what should you do if the system continually reboots and you can't read the error message produced on a blue screen
mr_godi [17]
I am fairly sure the command for boot options is F11, and if not, then power down the system manually and turn it back on
4 0
3 years ago
Read 2 more answers
Other questions:
  • Pointsyour company environment includes windows server versions 2003, 2008, and 2012. desktops range from windows xp and vista.
    13·1 answer
  • 6.67
    5·1 answer
  • You just brought a new hard drive for your computer. U plan to use this as a secondary hard drive to store all your uma files. O
    10·1 answer
  • Robert's employer has agreed to pay half the tuition for Robert to complete his college degree. This benefit is known as what?
    7·2 answers
  • dr. olson likes to conduct research on the nature of prejudice and its effect on behavior. dr olson is probably a (n) - psycholo
    8·2 answers
  • In troubleshooting a boot problem, what is the advantage of restoring all BIOS settings to their default values?
    6·1 answer
  • Cuales son las paginas web​
    12·1 answer
  • It is a blueprint of a project​
    9·2 answers
  • Join each of the follwing sentences using unless
    14·2 answers
  • When a computer is infected by a virus, _______.
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!