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
Leslie Is doing a sociological study of people who have live remote island. She interviews the people and than she observes them
dimulka [17.4K]
Making guesses, as opposed to the other answers, this is the only one that forges new ideas and doing such will only lead to an illegitimate conclusion/study.
5 0
3 years ago
Read 2 more answers
What is the portion of the PowerPoint window that contains the current slide, total slides, zoom options, and various shortcuts
telo118 [61]
Normal view is the answer
7 0
4 years ago
The Mail Merge Wizard can be found in the drop-down list of the _____ icon.
LuckyWell [14K]
It would have to be letter B.
5 0
3 years ago
Read 2 more answers
100POINTS!!!!
Anettt [7]

Answer:

Is it a tool in the computer, pls make it clear

6 0
3 years ago
Read 2 more answers
Guess the output #includes&lt;stdio•h&gt;
kondaur [170]
Hello. Is the one I work do.
3 0
3 years ago
Other questions:
  • The mean life of a certain computer hard disk in continual use is 8 years. (a) How long a warranty should be offered if the vend
    14·1 answer
  • Which best describe a resource each student could use to find information
    6·2 answers
  • Which is part of the dales process A customer retention B billing C cost planning D customer relations
    11·1 answer
  • The picture that graphically represents the items you use in Windows is called a/an
    15·1 answer
  • Josh's boss asked him to write a letter to their customers explaining some upcoming price increases. But Josh was in a hurry to
    8·2 answers
  • What Are the Components of a Web Address? *​
    14·2 answers
  • In one to two sentences, describe how you would add a new slide to your presentation.
    11·2 answers
  • in a stop-and-wait arq system, the bandwidth of the line is 1 mbps, and 1 bit takes 10 ms to make a round trip. if the system da
    12·1 answer
  • Core to resource management system is the _________that coordinates the server hardware.
    8·1 answer
  • A hub is a central computer true or false?
    13·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!