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
What is not a benefit of exploring tabs and groups in Microsoft Word?
MrRa [10]
Microsoft's<span> direct participation </span>not<span> only assures you that MOAC textbook content is accurate and current</span>
8 0
3 years ago
Read 2 more answers
Describe the difference between fuses and circuit breakers. where might each type of device find its best use? g
ycow [4]
Here i found this link that might help!
https://study.com/academy/lesson/the-differences-between-fuses-circuit-breakers.html

Have a nice day!
3 0
3 years ago
Many subject elements make for simple and streamlined looking images. true or false
sukhopar [10]

Answer:

Explanation:

false. many elements means a complicated picture, not a simple one.

8 0
2 years ago
In a spreadsheet, equations that use addition, subtraction, multiplication, and division operators, as well as values and cell r
timama [110]

The equations that uses addition, subtraction, multiplication and division operators and other values in a spread sheet is known as formulas. They are a way of having to provide symbols in means of expressing information regarding a mathematical formula that are being solved or showing its solution along with it.

4 0
3 years ago
Does anyone know what these two things are?
Sergio [31]
Cd and headphones :)
3 0
3 years ago
Read 2 more answers
Other questions:
  • Which of the following is not a general strategy for organizing and analyzing qualitative data?a.Convert the data into one or mo
    6·1 answer
  • Which of the following is 1000 of a second​
    15·1 answer
  • WHICH OF THESE IS A TYPE OF ETHERNET <br> 802.11AC <br> 1000BASET <br> 4G
    7·1 answer
  • What is the function of the command prompt?
    8·1 answer
  • Which is the first thing that would happen if a plant could NOT obtain carbon dioxide? A It would not be able to reproduce. B It
    5·1 answer
  • A(n) ____ is a grouping of related objects within a domain,
    15·1 answer
  • What is the difference between a workbook and a worksheet?
    14·2 answers
  • I need a computer science help.....and I rlly want it right now...this the question
    10·1 answer
  • Define two benefits to members of the community of replacing the printed copy with an online version.
    5·1 answer
  • QUESTION 44 To determine whether a character entered is a letter of the alphabet, use the ________ function. isdigit fromkeyboar
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!