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]
4 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]4 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
Explain the five design principles that cartographers use when designing a map.<br>HELP ASAP
Dovator [93]

Answer:

Five of the main design principles are legibility, visual contrast, figure-ground organization, hierarchical organization, and balance. Together these principles form a system for seeing and understanding the relative importance of the content in the map and on the page.

Explanation:

3 0
4 years ago
Billy needs to type a bibliography/reference page for the report that he just typed. Which paragraph format should he use?
Olin [163]
He should use a MLA format

3 0
3 years ago
Linda works from home occasionally and needs to set up her computer at work so she can remote in from her home office. Which too
qwelly [4]

Explanation:

Check the type of hard drive installed.

hope this helps you ❣️

4 0
3 years ago
Which of the following includes the part of the Internet that you typically see?
Serggg [28]
As for this problem about the part of the Internet, the most probable and the most likely to be the answer out of the options presented together with the problem is A. Interface.

<span>Interface would be the part of the Internet that you typically see. Interface is the widely known term used for GUI or Graphics User Interface. This covers about as to how you handle your desktop or computer. Basically, the moment the browser is opened, the interface appears. The other options are also arguable and that they might also pose the possibility of them being the correct answer taken as they are. Interface would cover them all and be the most likely answer.</span>
3 0
3 years ago
Janith is creating a spreadsheet with the names, locations, dates, and costs of summer camps she is interested in attending. Wha
motikmotik

Answer:

Hyperlink camp’s web page to the document  is the right answer.

Explanation:

Adding pictures will occupy more space, activity schedules might change time to time. So considering all these factors, it is better to go for adding hyperlink of the web page in the excel. The advantage here is that, if we keep all additional data in web, we can update content any time and the client can view at any time.

Also images are displayed best in web only. If we add additional column in excel, it might not work fine for adding pictures or menu. Even if we add additional worksheet, it might not satisfy the need.

6 0
4 years ago
Other questions:
  • Questions 6 - 9 Refer to the following code: public class WhatsIt { private int[] values; private double average; public WhatsIt
    7·1 answer
  • The font size on presentation slides should not be smaller than _____ -point.
    10·1 answer
  • Mobile ethnography can be especially useful for documenting public behavior, such as waking up in the morning or administrating
    9·1 answer
  • If you had a chance to see what your life would be like in 20 years
    8·1 answer
  • Pressing the Ctrl+Home keys moves the insertion point to the
    12·2 answers
  • How to find determinant of ​
    15·1 answer
  • An expansion ____ is a long-narrow socket on the motherboard into which you can plug an expansion card.
    12·1 answer
  • our grandmother tells you a dollar doesn’t go as far as it used to. She says the “purchasing power” of a dollar is much less tha
    6·1 answer
  • Create and configure databases in oracle database management system operation administration
    6·1 answer
  • As we’ve discussed, computer programs are considered creative works and are protected by copyright. That means those programs be
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!