Create a function of name body_type() that receives BMI value and return the body type according to the table below:BMI Value Body Typeless than 18.5 Underweightless than 24.9 Healthy weightless than 29.9 Overweightmore than or equal to 30 ObeseFor example:Test Resultprint("You are", body_type(18))You are underweightprint("You are", body_type(24))You are healthyprint("You are", body_type(29))You are overweightprint("You are", body_type(30))You are obese
Question
Create a function of name body_type() that receives BMI value and return the body type according to the table below:BMI Value Body Typeless than 18.5 Underweightless than 24.9 Healthy weightless than 29.9 Overweightmore than or equal to 30 ObeseFor example:Test Resultprint("You are", body_type(18))You are underweightprint("You are", body_type(24))You are healthyprint("You are", body_type(29))You are overweightprint("You are", body_type(30))You are obese
Solution
Sure! Here is a step-by-step guide to creating the body_type function in Python:
-
Define the function: Start by defining the function
body_typethat takes one parameter,bmi. -
Use conditional statements: Use
if,elif, andelsestatements to determine the body type based on the BMI value. -
Return the appropriate body type: Based on the conditions, return the corresponding body type as a string.
Here is the complete code:
def body_type(bmi):
if bmi < 18.5:
return "underweight"
elif bmi < 24.9:
return "healthy weight"
elif bmi < 29.9:
return "overweight"
else:
return "obese"
# Test cases
print("You are", body_type(18)) # You are underweight
print("You are", body_type(24)) # You are healthy weight
print("You are", body_type(29)) # You are overweight
print("You are", body_type(30)) # You are obese
Explanation:
-
Function Definition:
def body_type(bmi):This line defines a function named
body_typethat takes one argument,bmi. -
Conditional Statements:
if bmi < 18.5: return "underweight" elif bmi < 24.9: return "healthy weight" elif bmi < 29.9: return "overweight" else: return "obese"- If
bmiis less than 18.5, the function returns "underweight". - If
bmiis less than 24.9 but greater than or equal to 18.5, the function returns "healthy weight". - If
bmiis less than 29.9 but greater than or equal to 24.9, the function returns "overweight". - If
bmiis 30 or greater, the function returns "obese".
- If
-
Test Cases:
print("You are", body_type(18)) # You are underweight print("You are", body_type(24)) # You are healthy weight print("You are", body_type(29)) # You are overweight print("You are", body_type(30)) # You are obeseThese lines test the function with different BMI values and print the corresponding body type.
This function will correctly classify the body type based on the given BMI value according to the provided table.
Similar Questions
Create a function of name get_bmi() that receive the weight in kilograms and height in centimeter of a person and return his or her Body Mass index (BMI). The function should convert the height to meters before calculating the BMI.Height in meter = height in centimeter / 100BMI = weight in kilogram / (height in meter * height in meter)For example:Test Resultprint("BMI value:", round(get_bmi(60, 160),1))BMI value: 23.4print("BMI value:", round(get_bmi(85, 170),1))BMI value: 29.4
Consider you are working in the Hospital and find the Obesity of outpatients, which you need to check Body Mass Index (BMI) for each customer and BMI is found by taking your weight in kilograms and dividing by the square of your height in meters. The BMI categories are:• Under weight: <18.5• Normal weight: 18.5–24.9• Over weight: 25–29.9• Obesity: BMI of 30 or greaterUse class, object, constructor, attributes, and methods.( 1 inch=2.5 cm) Testcase Input 1:Raja5564.96OutputNormal weight
Problem StatementBalaji wants your help to design a fitness calculator. The simple measure of body fitness is the BMI or Body Mass Index. It depends only on the height L and weight W of a person. It is defined as BMI = [weight / height2] where weight is taken in kilograms and length in meters. Four general grades are proposed:Underweight[U] - when BMI < 18.5Normal weight[N] - 18.5 <= BMI < 25.0Heavyweight [H] - 25.0 <= BMI < 30.0Overweight [O] - above or equal to 30.0Write a program that takes in the Weight (in Kg) and Length (in meters) of an individual and displays the grade as U, N, H, O.Note: Store all the variables in register memory.Input format :The first line of input consists of an integer, representing the weight.The second line consists of a double value, representing the height in meters.Output format :The output displays the grade based on the given conditions.Refer to the sample output for the formatting specifications.Code constraints :In the given scenario, the test cases will fall under the following constraints:60 ≤ weight ≤ 2001.0 ≤ height ≤ 5.0Sample test cases :Input 1 :1303.5Output 1 :UInput 2 :2002.7Output 2 :HInput 3 :902.1Output 3 :NInput 4 :741.3Output 4 :O
Define a function stat(gender, age, height, mass) that returns weight, meter, centimeter, and bmr, in which:Use the variables defined in the input (age, height, mass) and s_value, to implement the formula for BMR: bmr = 10.0 * mass + 6.25 * height - 5.0 * age + s_valueCreate a new variable weight that measures the mass in 斤. Use the conversion factor 1 kilogram = 2 斤.Create a new variables meter and centimeter each represented as integers. Those value should be computed by using one Python arithmetic operator on the variable heightExpected outputAssume mass = 55, height = 160, age = 22, s_value = -161, once you call the function,stat(gender, age, height, mass)The expected output should be:(110, 1, 60, 1279.0)
BMI CalculatorCreate an application which calculates BMI (Body Mass Index)Your app should have 2 input boxesTake weight in kgs from userTake height in meters from userBased on entered height and weight calculate BMI of that personHere is the formula for manually calculating BMI BMI = (weight) / (height * height)From the obtained BMI result, display whether the person isUnderWeight - bmi <= 18.4Normal Weight - bmi >= 18.5 && bmi <= 24.9Overweight - bmi >= 25 && bmi <= 29.9Obese - bmi >= 30Hint: use If conditionsSample Output
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.