Write a Python 3 program that inputs three weights and heights and outputs three body mass indices (BMIs), one corresponding to each (weight, height) input pair. Process the three input pairs with a loop. Compute BMI with the following formula: (weight * 703) / height^2. Python has an exponentiation operator, which you MUST use. Print calculated BMIs to two decimal places. Use the CPython implementation of the Python language (it is the one installed on the Linux Lab machines).
Include a function named "bmi" to compute BMI given a weight in pounds and height in inches. Your function should return the computed BMI.
Include a comment block at the top of the program and other comments in your code.
After you finish printing the three BMIs, print the bytecode corresponding to the "bmi" function (and ONLY this function). Print the code as a string, and also as a sequence of integers in square brackets. Next, use the "dis" module to disassemble the bytecode to display instructions and operands in a more readable format.
Lastly, answer the questions below.
Input three weights and three heights. Weight will be in pounds and height will be in feet and inches. All inputs will be integers. Feet and inches will be typed on the same line.
Output the BMI using a field width of five with two decimal places.
Use PRECISELY the format shown below with the EXACT same spacing and spelling.
Sample Input and Output (ellipses show truncations)
Weight ==> 200 Height ==> 6 4 BMI = 24.34 Weight ==> 180 Height ==> 6 0 BMI = 24.41 Weight ==> 190 Height ==> 6 1 BMI = 25.06 ****************** Bytecode for "bmi" ****************** b'|\x00d\x01\x14\x00... [124, 0, 100, 1, 20, 0, ... ********************* Disassembly for "bmi" ********************* 6 0 LOAD_FAST 0 (weight) ...
Answer these questions in a PLAIN TEXT file named "README.txt". Include the QUESTIONS in the file as well. Use whitespace for readability, and keep lines to AT MOST 80 characters.
Discuss how the bytecode corresponds to the disassembled code, AND how the disassembled code corresponds to the Python source code.
Discuss AT LEAST TWO benefits of CPython's implementation, which compiles Python to bytecode, and then interprets the bytecode. Is this similar to how Java is typically implemented? Explain.
There are several types of bytecode instructions, like "General instructions", "Binary operations", and "Miscellaneous opcodes" (see the dis module documentation). Discuss how one instruction of each of the three types above is executed. Limit your instruction choice from the set of instructions generated by the "dis" module (if possible). Specifically cite relevant code from ceval.c.
Submit your Python code (use a ".py" extension) and "README.txt". Use the "submit" utility to submit your code.