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
What is the output of the following code?<br> print (12 // 6)
sveta [45]

Answer:

2

  • See here we have //
  • // means floor division in python.
  • It gives us only the integer part not floating or decimal.

So

12//6=2

8 0
2 years ago
Why is UDP less reliable than TCP?
borishaifa [10]

Answer:

a.) UDP does not include data reassembly.

7 0
3 years ago
Read 2 more answers
The size of the board is one of the differences between Elevens and Thirteens. Why is size not an abstract method?
Levart [38]

Answer:

The program keeps track of the size of the board in cards.size(). The sub class sets this by passing it into the constructor. After that, the subclass never cares about the size of the board, so it's not necessary to make it accessible with an abstract method. Any need for it is covered by cardIndexes method.

Explanation:

The differences between Elevens and Thirteens

The program keeps track of the size of the board in cards.size(). The sub class sets this by passing it into the constructor. After that, the subclass never cares about the size of the board, so it's not necessary to make it accessible with an abstract method. Any need for it is covered by cardIndexes method.

5 0
3 years ago
PART 2 - Exercise 2 - Programming Assignment
Oliga [24]

Suppose that a linked list is used as a data structure for the hash table, create a program that includes steps his application counts the number of phrases in documents decided on via way of means of the user #include.

<h3>What is Programming?</h3>

It is the manner of making hard and fast commands that inform a pc the way to carry out a task. Programming may be finished the usage of lots of pc programming languages, inclusive of JavaScript, Python, and C++.

  1. This application counts the quantity of phrases in documents decided on via way of means of the user.
  2. #include
  3. #include
  4. #include the usage of namespace std; //Function 1 int count(string word)go back word.size();
  5. }
  6. //Function 2
  7. int vowel(string word)> filename;
  8. //Open the {input|enter">enter file.
  9. inputfile.open(filename.c_str()); cout<<"nWord listing after format";
  10. cout<<"n____nn"; //If the file succesfully opened, process it.if (inputfile).

Read more about program :

brainly.com/question/1538272

#SPJ1

5 0
2 years ago
A ___________ is similar to an intranet in that it uses internet technologies, but is developed for users outside the organizati
Vanyuwa [196]
The blank is extranet
I hope this helped!
6 0
3 years ago
Other questions:
  • Need answers for 11&amp;12. Due today. Thanks.
    14·1 answer
  • If a user has just added a simple triangle shape into a diagram, how can the triangle be adjusted? Check all that apply. by maki
    6·2 answers
  • What is a symptom of a failing power supply? The display has only a blinking cursor. The computer displays a POST error code. Th
    12·1 answer
  • Using C++
    15·1 answer
  • How do you put a picture when you ask a question?
    6·2 answers
  • In addition to format commands that are found in the ribbon, which option is available for more extensive formatting?
    11·1 answer
  • Which describes the first step a crawler-based search engine uses to find information?
    14·2 answers
  • What keyword must be used on any method (function) on your class that is called from your main() method?
    15·1 answer
  • Write a public member function which replace that replaces one occurrence of a given item in the ArrayBag with another passed as
    14·1 answer
  • Stephanie would like to know the average number of regular hours worked by her employees. In cell B11, create a formula using th
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!