Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In this assignment we will practice using a module and a class that have been given to us . You are provided with a file

In this assignment we will practice using a module and a class that have been given to us.
You are provided with a filefood.py(see attached file later). This file contains code that implements a very basic food item object. It has a constructor, getter, setter, and helper methods. Take a look at theFoodItemclass and familiarize yourself with those methods.
You are also provided with a fileinputroutines.py(not shown). You will use two functions in this file to handle input validation. While you cannot view theinputroutines.pyfile, your program can access its content by importing it. The two functions in the file which are relevant to this assignment are documented below:
Function: intInRange(lower, upper)
Purpose: read an integer from keyboard and validate that is a value between lower and upper
Parameters: lower and upper are two integers to represent lower and upper bounds
Return value: a valid integer entered by the user
Sample call: value = intInRange(0,100)
Function: floatInRange(lower, upper)
Purpose: read a float from keyboard and validate that is a value between lower and upper
Parameters: lower and upper are two float to represent lower and upper bounds
Return value: a valid float entered by the user
Sample call: value = floatInRange(5.50,25.00)
Your task is to write the main script that creates aFoodItemobject, displays the basic object's information, then ask the user how many servings they have consumed and display the total calories consumed.
Here are some additional specifications:
* The user of the program must provide the food item's name, serving size, grams of fat, carbs, and protein per serving.
* Serving size is an integer value between 0 and 500(inclusive).
* Grams of fat per serving is a float value between 0.00 and 50.00(inclusive).
* Grams of carbs per serving is a float value between 0.00 and 50.00(inclusive).
* Grams of protein per serving is a float value between 0.00 and 50.00(inclusive).
* Instantiate aFoodItemobject with the data provided by the user.
* Display theFoodItem's name, serving size, grams of fat, carbs, and protein per serving, as well as the number of calories per serving.
* Next the user should enter the number of servings consumed
* The number of servings is an integer value between 0 and 10(inclusive).
* Calculate and display the total number of calories consumed.
Notes
* Floating-point values must be displayed with 2 decimal digits after the decimal point.
* You are not allowed to modify thefood.pyfile or theFoodItemclass.
* Make sure you include a header comment at the top of your file.
Below there are a couple of sample runs:
Enter food item's name: Chocolate Bar
Enter the serving size in grams (or mL for liquids): 44
Enter the grams of fat per serving: 13.0
Enter the grams of carbs per serving: 26.0
Enter the grams of protein per serving: 3.4
Nutritional information per serving of Chocolate Bar
Serving Size: 44 grams / mL
Fat: 13.00 grams
Carbohydrates: 26.00 grams
Protein: 3.40 grams
Number of calories for 1 serving: 234.60
Enter the number of servings consumed: 2
Number of calories for 2 serving(s): 469.20
Enter food item's name: Whole Milk
Enter the serving size in grams (or mL for liquids): 240
Enter the grams of fat per serving: 8.0
Enter the grams of carbs per serving: 12.0
Enter the grams of protein per serving: 9.0
Nutritional information per serving of Whole Milk
Serving Size: 240 grams / mL
Fat: 8.00 grams
Carbohydrates: 12.00 grams
Protein: 9.00 grams
Number of calories for 1 serving: 156.00
Enter the number of servings consumed: 3
Number of calories for 3 serving(s): 468.00
* You may find the following site useful to compare your output against the expected program output:Diffchecker
* The purpose of this problem is to practice using classes and modules.
* Please make sure to submit a well-written program. Good identifier names, useful comments, and spacing will be some of the criteria that will be used when grading this assignment.
* This assignment can be and must be solved using only the materials that have been discussed in class. Do not look for alternative methods that have not been covered as part of this course.
How your program will be graded:
* correctness: the program works and performs all tasks correctly: 50%(autograded by Zybooks)
* complies with requirements (input validation, correct use of theFoodItemclass methods): 40%(TAs)
* code style: good variable names, comments, proper indentation and spacing: 10%(TAs)
# TO-DO: your header comment goes here
# TO-DO: import the modules needed to use the FoodItem class the and input validation functions
# main routine
if __name__=="__main__":
# TO-DO: WRITE THE MAIN ROUTINE HERE

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Expert Oracle9i Database Administration

Authors: Sam R. Alapati

1st Edition

1590590228, 978-1590590225

More Books

Students also viewed these Databases questions

Question

What do you mean by dual mode operation?

Answered: 1 week ago

Question

Explain the difference between `==` and `===` in JavaScript.

Answered: 1 week ago

Question

In what ways are you similar to your closest friends?

Answered: 1 week ago