Answered step by step
Verified Expert Solution
Question
1 Approved Answer
**************************** Help please This question assesses Block 2 Part 4. Parts a and b of this question involve creating drawings or descriptions. You can make
**************************** Help please
This question assesses Block 2 Part 4. Parts a and b of this question involve creating drawings or descriptions. You can make your drawings whichever way is easiest or fastest for you. For instance, you could simply make your drawings using pencil and paper then scan or photograph them. Alternatively, you can answer by providing descriptions of the drawings. In that case, keep close to the formulations used in the long figure descriptions of the examples given in Section 4.5 of Block 2 Part 4. a. Consider the following lines entered on the Python shell: Q4_TMAO2 = 'submitted' id(Q4_TMAO2) 1944127298928 type(Q4_TMAO2) \&lass 'str'> Q4_TMAO2 'submitted' Draw (or describe) the object and its label that the Python interpreter creates in response to the assignment Q4_TMAO2 = 'submitted' in the interactive shell above. Your drawing or description should include a String object with a similar level of detail as Figure 4.14 in Section 4.5.1 (page 216) and a label. Include your drawing or text description of the object and label in the solution document. (2 marks) b. Consider the following two assignments: - my_module =[ 'Part', '1', 'Block', '2', 'TMAO2' ] - my_module [1]=4 Draw (or describe) the objects and labels that the Python interpreter creates in response to the first assignment. Then draw (or describe) the objects and labels that results from carrying out the second assignment immediately after the first assignment. Include your drawings or text descriptions in the solution document. (4 marks) c. This part provides you with an opportunity to demonstrate your understanding of the problem-solving approach taught in TM112 and Python functions. Decomposition and algorithms are covered in Block 1 Parts 2 and 4 and Block 2 Part 2. Further examples can be found in Block 2 Part 4 . How to define your own functions is introduced in Block 2 Part 4 Section 4.1.3. You will need an individual number in order to answer this question part. You should find your individual number as shown below before you start the question itself. How to obtain your individual number Perform the following steps with pen and paper - you should not write code for these steps: 1. Write down your PI (Personal Identifier). Your PI will be different from your OUCU, but like your OUCU it is unique to you. The PI starts with a letter followed by 6 digits, followed by a check value, which is either a digit or letter. 2. Identify the last three numerical digits that occur in your PI. So, for instance, if your Open University PI is A987654X, you'd take 654. If your PI is Z1234567, you'd take 567. 3. Use the three digits from Step 2, let's call them XYZ, to create the number 1.01XYZ. For instance, if you obtained 654 in Step 2, then you now get 1.01654. If you obtained 567 , you now would get 1.01567. In your solution document, in answer to Part ii below, write down your PI and the individual number that you have obtained via Steps 1-3 from your PI. We ask you to make use of the individual number based on your PI so you can demonstrate that your solution to this question part is your own. If you are unclear about how to use your PI to arrive at the individual number, do not hesitate to ask your tutor for advice. Please state your full PI and the individual number you obtained, so your tutor can establish that the digits you use for XYZ in 1.01XYZ correspond with the final three digits of your PI. In this question part, you will develop an algorithm which performs nutritional calculations by estimating total calories in order to assist users in managing their intake of calories. You should read the question all the way through before you start, to make sure that you understand the scenario. Background to the problem: A nutritional app assists users in assessing their dietary habits. For the purpose of evaluation, the app asks the members to report how many fat grams and how many carbohydrate grams they consume per day. To help users manage their calorie budgets more effectively, the app calculates the total calories derived from fat and carbohydrates, rounded to the nearest calorie. The problem: The purpose of this question is to write a program that will perform these nutritional calculations. Specifically, you will produce an estimate of the total calories as follows: calestimated=1.01XYZcaltotal=1.01XYZ(calfat+calcarb) The number of calories resulting from the fat are calculated by multiplying the fat grams by 9 . calfat=fatgr9 Similarly, the number of calories that result from the carbohydrates are calculated as the carbohydrates grams multiplied by 4 . calcarb=carbgr4 Your individual number is tied to the total calories so that there is some margin of error in the estimates. For example, if a member reported fat frgr=150 of fat and carb gr=300 of carbohydrates on a day and the individual number is 1.01123 then: calestimatedcalestimated=1.01123(1509+3004)=2579calories(roundedtothenearestcalorie) i. Develop an initial decomposition of the problem using the chevron notation (> and > ) from the module materials. Include your decomposition in your solution document. ii. Building on your decomposition for part c.i., develop an algorithm for solving the problem. Include this algorithm in your solution document, and also write down your PI and the individual number that you have obtained via Steps 1-3 from your PI. iii. Write a Python function definition following the instructions that are provided below. Save your function in a file called Q4_OUCU.py, where 'OUCU' is your OUCU number. When you have completed your work on this part: - submit the .py file with your function - paste the function definition from your .py file as text (with indentation preserved) into your solution document Instructions for writing the function: - Provide a single Python function that implements the algorithm you wrote for part c.ii. Your function must be a translation of your algorithm from part c.ii., otherwise no marks will be awarded. - The function should have two arguments: one for the fat grams fat grgr and one for the carbohydrates grams carb gr. - The function should have one return value for the estimated calories cal estimated,, which is an integer. iv. Test the function by calling it with the arguments 150 and 300 in your Python program. Paste the function call and the result as text into your Solution document. You should aim to use only the Python features that are introduced in the module. If you decide to use techniques or language features that TM112 does not cover, you must give a justification for your decisions, otherwise marks will be lostStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started