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
When an attacker presents a program or himself as someone else to obtain private information and pretends to be a legitimate web
timofeeve [1]
A spoofing attack. "<span>a situation in which one person or program successfully masquerades as another by falsifying data, thereby gaining an illegitimate advantage."</span>
8 0
3 years ago
If you weigh 100 pounds, and your 150 pound big sister is sitting 15 feet from the fulcrum of a seesaw, how far from the fulcrum
Dahasolnce [82]

Answer:

22.5

Explanation:

My weight = 100 pounds

Sister's weight = 150

Distance from fulcrum = 15 ft

Distance has an inverse proportion with weight

Distance = k/w

Where k is a constant

K = distance x weight

K = 100 x distance

150 x 15 = 100 distance

2250 = 100 distance

Divide through by 100 to get distance

2250/100 = distance

Distance = 22.5

5 0
3 years ago
How far is florida from oklahoma?
leonid [27]
Florida is 1,344.8 miles from oklahoma
7 0
3 years ago
Read 2 more answers
A(n) ________________ is a software tool for specifying the content and format for a database report.
Alex_Xolod [135]
A report generator is a software tool for specifying the content and format for a database report. It is a program where it takes data from a database and use it in producing a file that can be understood by humans. These databases include XML stream, OpenCover, PartCover and the like.
7 0
3 years ago
A security engineer is configuring a system that requires the X.509 certificate information to be pasted into a form field in Ba
zavuch27 [327]

Answer:

PFXB

Explanation:

3 0
3 years ago
Other questions:
  • Do Violent Video Games Make People More violent in Real Life ?
    14·1 answer
  • In JavaScript, which of the statements below can be used for string declaration?
    11·1 answer
  • Why aren’t I leveling up? I have enough points and even a brainliest. Could an expert please help me!! I am really confused.
    10·1 answer
  • Halp Computer Science
    12·2 answers
  • You are reviewing the output of the show interfaces command for the Gi0/1 interface on a switch. You notice a significant number
    12·1 answer
  • Initialized the variable with the value 0
    11·2 answers
  • Question # 5
    6·1 answer
  • 16. If a user can make modifications to database objects, what permission has that
    13·1 answer
  • Every time a key is pressed on the keyboard, the _______________ chip in the keyboard notices which key has been pressed.
    13·1 answer
  • Award documentation is typically required to be prepared and submitted within how long after the end of a project period:_____.
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!