Program should start by asking for the patient id (which is a six-digit positive integer with no leading zeroes). When a valid patient id is entered, your program must ask for the amount of protein, carbohydrates, and fat required by that patient (which must all be non-negative numbers). These values must then be passed to a function named choose_diet (described below), which returns the name of the diet that best meets the nutritional needs of the patient. Your program should then output a message informing the user of the best diet for the patient, as well as appending the patient id, followed by a comma (i.e. ,), and then the name of the best diet for that patient to a file named meals.csv (in the current directory). Your program should repeat this process (i.e. asking for a new patient id) until the patient id entered by the user is blank, in which case your program should exit.
Selecting the best diet for a patient
The diets that have been identified as adequately meeting the needs of patients are:
Diet Protein (g) Carbohydrates (g) Fat (g)
Normal 32.50 60.00 40.86
Oncology 35.00 52.50 37.63
Cardiology 32.50 30.00 26.88
Diabetes 20.00 27.50 27.95
Kidney 15.00 55.00 23.65In order to select the most appropriate diet for a given patient, program requires a function named choose_diet that takes the following parameters (in order):
Parameter name Description
protein The amount of protein (in grams) required by the patient
carbohydrates The amount of carbohydrates (in grams) required by the patient
fat The amount of fat (in grams) required by the patient
For each possible diet, the choose_diet function will calculate the error between the patient’s requirements and the nutrition provided by the diet, returning the name of the diet with the lowest error. The error must be calculated by a function named calculate_errorthat takes the following parameters (in order):
Parameter name Description
diet A dictionary that includes the keys “protein”, “carbohydrates”, and “fat” which represent the values provided by a diet (note: the dictionary may include other keys)
requirements A dictionary that includes the keys “protein”, “carbohydrates”, and “fat” which represent the amounts required by the patient (note: the dictionary may include other keys)
The value returned by calculate_error must be the absolute value of the difference between the protein values from diet and requirements plus the absolute value of the difference between the carbohydrates values from diet and requirements plus the absolute values of the difference between the fat values from diet and requirements.
choose_diet will use the values returned by calculate_error to determine the diet with the lowest error for the given patient requirements. choose_diet must then return the name of the diet with the lowest error as its return value.
Ask Your Question
We have verified professionals who are ready to answer your question.
Save Time and Money
We choose experts who can quickly answer your question and that suit your budget.
Get Your Answer
Your satisfaction is 100% guaranteed. You can keep on asking questions until you get the answer you need.