Question
This Python Programming problem involves four steps to complete with specific instructions in each step. Please write in clean code , which includes: No obsolete
This Python Programming problem involves four steps to complete with specific instructions in each step.
Please write in clean code, which includes:
No obsolete lines of code: o No print statements in the function o No code which has no impact on the return value No input statements in the function
Function and class names are identical to the names specified in the questions.
**Here are the four steps:
Step 1 - unittest
*Using the unittest module, write test method called:
test_bmi_returns_bmi_when_positive_integers_are_passed
The test method should be included in a TestCase class called TestBmi. It should call a function called bmi, passing two positive integers as arguments. The two arguments passed to the bmi function represent a person's weight in kg and height in cm (in this order).
The test method should verify that the value returned from the bmi function matches the body-mass index (BMI) for the given weight and height. The BMI is defined as the body weight divided by the square of the body height, and is expressed in units of kg/m2.
*NOTE: The BMI formula assumes height in meters, while the bmi function's second argument represents a person's height in centimeters (1m = 100cm).
Step 2 - Lambda Functions
Write lambda function called bmi that calculates a person's body mass index (BMI), according to the definition of BMI given in Exercise 1.
-Inputs: 1. A positive integer, representing a person's weight in kg 2. A positive integer, representing a person's height in cm
-Output: A positive float, representing a person's BMI
*Verify that your implementation of the bmi function makes the test from Exercise 1 pass.
*Note: Do not perform validation on any of the parameters. That's the responsibility of bmi's caller function.
Step 3 - Comprehensions
Write function called list_bmi which returns a list of BMIs obtained from a list of tuples provided as argument. Each tuple inside the input list contains two items: the first represents a person's weight in kg, while the second represents the same person's height in cm.
-Input: A list of tuples, each containing two positive integers (weight and height) -Output: A list of floats, representing the BMI values for each (weight, height) tuple
You must use list comprehensions, along with the bmi function created in exercise 2, to produce the output list. Failure to use comprehensions will result in zero points, even if your method returns the right output.
*Note: Do not perform validation on any of the parameters yet.
Step 4 - unittest
Using the unittest module, write test method called:
test_list_bmi_raises_InvalidInputError_when_any_number_not_positive
The test method should be contained in a TestCase class called TestListBmi and it should test the list_bmi function from Exercise 3.
The test method should verify that, passing a list of tuples of two integers each to the list_bmi function raises an InvalidInputError exception, when either one of the integers in any one of the tuples is non-positive.
After youve written the test, you should modify the list_bmi function from Exercise 3, so that the test will pass.
Step 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