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
A general rule for adding text to a slide is ____.
Rama09 [41]

A general rule for adding text to a slide is to use not more than two fonts in a presentation and vary the font size. Furthermore, to make a slide legible, in addition to the point size, attention must be paid to the word count per slide, the choice of typeface, and the visual balance of  space to text.

4 0
3 years ago
Read 2 more answers
When you ____ software, you are adapting it from one type of computer or operating system to run on a different computer or oper
ra1l [238]

Answer: Port

Explanation :

When we port a software from one computer to another computer or from one operating system to another operating system, it tries to adapt to the new environment of the machine by checking the required the configurations of the machine and then checking the available files in the software to run the machine.

The porting of a software also checks whether the software is compatible with the machine or not and if not then why.

7 0
3 years ago
which of the following is not a name of one of the central features of Facebook timeline activity log Graph Search for Daily New
Pani-rosa [81]
The correct answer is Graph Search for Daily News

This does not exist on Facebook, unlike the timeline and the activity log.
3 0
3 years ago
When an instruction is sent to the CPU in a binary pattern, how does the CPU know what instruction the pattern means
kozerog [31]

Answer:

When an instruction is sent to the CPU in a binary pattern, how does the CPU know what instruction the pattern means

Explanation:

When the CPU executes the instructions, it interprets the opcode part of the instruction into individual microprograms, containing their microcode equivalents. Just so you know, a full assembly instruction consists of an opcode and any applicable data that goes with it, if required (register names, memory addresses).

The assembly instructions are assembled (turned into their binary equivalent 0s and 1s, or from now on, logic signals). These logic signals are in-turn interpreted by the CPU, and turned into more low-level logic signals which direct the flow of the CPU to execute the particular instruction.

8 0
3 years ago
What is the preferences of occupation in ones life?
umka21 [38]

Answer:

mark me brai list i request u

6 0
2 years ago
Other questions:
  • The term integration refers to the ability to
    6·1 answer
  • A technician mistakenly uninstalled an application that is crucial for the productivity of the user.
    6·1 answer
  • Give two separate print statements: one will print your name, the other will print your major. Ensure that both will print on th
    15·1 answer
  • Read the four detective reports and the combined affidavit and warrant for the M57 Patents case. Write a one- to two-page paper
    5·1 answer
  • Thank you very much for your email. ...... was very interesting​
    15·1 answer
  • Ania has written this SimpleStopwatch class. In which line is she measuring the elapsed time?
    13·1 answer
  • Select the statement which most accurately describes the benefits and drawbacks of working from home and telecommuting.
    13·2 answers
  • Write a Python function that takes as input a list, A, and returns two lists L and G. L constains all numbers in A, which are no
    13·1 answer
  • Which feature is not in ms PowerPoint​
    12·1 answer
  • Question 4 of 25
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!