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
HIPAA protects which of the following kinds of data?
Gelneren [198K]
The answer is a i looked up the question and it says a
5 0
3 years ago
Read 2 more answers
What are the coordinates of the origin point? (Select the best answer.)
siniylev [52]

Answer:

1,10

Explanation:

7 0
3 years ago
A Chief Security Officer (CSO) has asked a technician to devise a solution that can detect unauthorized execution privileges fro
VikaD [51]

A solution which would best meet the CSO's requirements is: B. Sandboxing.

<h3>What is a sandbox?</h3>

A sandbox can be defined as an isolated environment in a computer system or on a network that is designed and developed to mimic end user operating system (OS) and environments, so as to detect unauthorized execution privileges from the operating system (OS).

In cybersecurity, sandboxing is typically used to safely execute suspicious code and data files without causing any harm to the host device or network. Also, sandboxing can work in conjunction with proxies or unified threat management (UTM).

Read more on sandboxing here: brainly.com/question/25883753

8 0
2 years ago
Identify the programmer’s responsibility in maximizing the programs reliability by having awareness of the beneficial and harmfu
trapecia [35]

Programmers can maximize the reliability of their programs by means of functional analysis.

The form in which programmers can <em>maximize</em> the reliability of their programs in accordance with the awareness of the beneficial and harmful impact on society, economies and cultures is how well they did processes of functional analyses, in which they investigate on market and client needs and derive <em>functional</em> and <em>non-functional</em> parameters, which define the scope and characteristics of the program.

A good functional analysis has an influence of about 80 % on success of programs on fulfilling existing needs and solving existing problems with a <em>reasonable</em> efforts.

We kindly invite to check this question on functional analysis: brainly.com/question/23731043

8 0
2 years ago
Im trying to type in answers but where the text box is supposed to be it says unlock answers. What does that mean?
borishaifa [10]
You may have to pay or sign up for the text box or if it is a computer program you may need to get the full version of the software if it is a trial
3 0
2 years ago
Other questions:
  • Do Violent Video Games Make People More violent in Real Life ?
    14·1 answer
  • To enter a typed number into a cell, you press Tab or Backspace?​
    7·2 answers
  • What is the decrypted binary
    9·1 answer
  • Write an if statement that prints the message ""The number is not valid"" if the variable distance is outside the range 100 thr
    8·1 answer
  • An algorithm that could execute for an unknown amount of time because it depends on random numbers to exit a function may:______
    13·1 answer
  • Which of the following represents knowledge as a set ofâ rules? A. Neural networks.B. Machine learning systems.C. Robotics.D. Ex
    11·1 answer
  • Three reasons Why we connect speakers to computers
    15·2 answers
  • BRIANLIEST!!!!!!!!!!!!!!!!
    12·2 answers
  • Software that converts program written in other language into machine language​
    11·1 answer
  • 3. is the system of rules that govern the ordering of values? culture a. Ethics b. organization c. protocol d. value system 3 .
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!