or this part of the assignment, you will create functions to calculate a person's body mass index (BMI). The formula you must use for this calculation is: BMI= (weight/height * height) **************Where weight is measured in kilograms and height is measured in meters. Do This: Write two functions: bmi() and imperial_bmi() that computes and returns the body mass index (BMI) of an individual. The first function - bmi takes the height and weight using metric measurements (centimeters and kilograms) and the second function (imperial_bmi) uses imperial measurements (inches and pounds). We will be using the auto-grader for this part of the assignment so your functions must match the specs precisely. Note: The BMI (metric) formula (given above) uses meters but our function for the bmi() takes centimeters as one of its parameters: bmi(height, weight): ''' Function -- bmi Takes as input height and weight in cm and kg and returns the BMI value Parameters: height (in cm) weight (in kg) Returns a float value representing the calculated bmi ''' imperial_bmi(height, weight): ''' Function -- imperial_bmi Takes as input height in inches and weight in pounds & returns the BMI value Parameters: height (in inches) weight (in pounds) Returns a float value representing the calculated bmi ''' Note: You do NOT need to provide a main() for this part of the assignment. You may write other "helper" functions if you wish (make sure you import any extra files you create AND include those files in your homework submission), but you must provide the bmi() and imperial_bmi() functions precisely as specified here. Note: You must use the measurement_conversion functions provided (you tested them thoroughly, right?). Hardcoding conversion values in your solution will result in marks being deducted from your grade. STARTING CODE INCHES_TO_CM = 2.54 POUNDS_TO_KG = 0.453592 def inches_to_cm( inches ): ''' Function -- inches_to_cm Converts inches to centimeters and returns (answers) the resulting value Parameters: inches (float) -- the original distance/height in inches Returns a float value representing the original vaule converted to centimeters ''' return abs(inches * INCHES_TO_CM) # convert negative distance to positive def cm_to_inches( centimeters ): ''' Function -- cm_to_inches Converts centimeters to inches and returns (answers) the resulting value Parameters: centimeters (float) -- the original distance/height in centimeters Returns a float value representing the original vaule converted to inches ''' return abs(centimeters * (1 / INCHES_TO_CM)) def pounds_to_kg( pounds ): ''' Function -- pounds_to_kg Converts pounds to kilograms and returns (answers) the resulting value Parameters: pounds (float) -- the original weight in pounds Returns a float value representing the original vaule converted to kilograms ''' return abs(pounds * POUNDS_TO_KG) # convert negative weight to positive def kg_to_pounds( kg ): ''' Function -- cm_to_inches Converts kilograms to pounds and returns (answers) the resulting value Parameters: centimeters (float) -- the original weight in kilograms Returns a float value representing the original vaule converted to pounds ''' return abs(kg * (1 / POUNDS_TO_KG))
For this part of the assignment, you will create functions to calculate a person's body mass index (BMI).
The formula you must use for this calculation is:
BMI= (weight/height * height)
**************Where weight is measured in kilograms and height is measured in meters.
Do This: Write two functions: bmi() and imperial_bmi() that computes and returns the body mass index (BMI) of an individual. The first function - bmi takes the height and weight using metric measurements (centimeters and kilograms) and the second function (imperial_bmi) uses imperial measurements (inches and pounds).
We will be using the auto-grader for this part of the assignment so your functions must match the specs precisely.
Note: The BMI (metric) formula (given above) uses meters but our function for the bmi() takes centimeters as one of its parameters:
bmi(height, weight):
'''
Function -- bmi
Takes as input height and weight in cm and kg and returns
the BMI value
Parameters:
height (in cm)
weight (in kg)
Returns a float value representing the calculated bmi
'''
imperial_bmi(height, weight):
'''
Function -- imperial_bmi
Takes as input height in inches and weight in pounds &
returns the BMI value
Parameters:
height (in inches)
weight (in pounds)
Returns a float value representing the calculated bmi
'''
Note: You do NOT need to provide a main() for this part of the assignment. You may write other "helper" functions if you wish (make sure you import any extra files you create AND include those files in your homework submission), but you must provide the bmi() and imperial_bmi() functions precisely as specified here.
Note: You must use the measurement_conversion functions provided (you tested them thoroughly, right?). Hardcoding conversion values in your solution will result in marks being deducted from your grade.
STARTING CODE
INCHES_TO_CM = 2.54
POUNDS_TO_KG = 0.453592
def inches_to_cm( inches ):
'''
Function -- inches_to_cm
Converts inches to centimeters and returns (answers) the resulting
value
Parameters:
inches (float) -- the original distance/height in inches
Returns a float value representing the original vaule converted
to centimeters
'''
return abs(inches * INCHES_TO_CM) # convert negative distance to positive
def cm_to_inches( centimeters ):
'''
Function -- cm_to_inches
Converts centimeters to inches and returns (answers) the resulting
value
Parameters:
centimeters (float) -- the original distance/height in centimeters
Returns a float value representing the original vaule converted
to inches
'''
return abs(centimeters * (1 / INCHES_TO_CM))
def pounds_to_kg( pounds ):
'''
Function -- pounds_to_kg
Converts pounds to kilograms and returns (answers) the resulting
value
Parameters:
pounds (float) -- the original weight in pounds
Returns a float value representing the original vaule converted
to kilograms
'''
return abs(pounds * POUNDS_TO_KG) # convert negative weight to positive
def kg_to_pounds( kg ):
'''
Function -- cm_to_inches
Converts kilograms to pounds and returns (answers) the resulting
value
Parameters:
centimeters (float) -- the original weight in kilograms
Returns a float value representing the original vaule converted
to pounds
'''
return abs(kg * (1 / POUNDS_TO_KG))
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 2 images