BMI calculator:
BMI is a quick and inexpensive way to categorize a person's weight as underweight, normal, overweight, or obese.
BMI formula:
BMI is calculated by dividing weight by height squared:
Metric units:
BMI = weight (kg) / [height (m)]2
US customary units:
BMI = weight (pounds) / [height (in)]2 x 703
Example:
# Input the weight in kilograms
weight = float(input("Enter your weight (in kg): "))
# Input the height in meters
height = float(input("Enter your height (in meters): "))
# Calculate BMI using the formula:
bmi = weight / (height ** 2)
# Output the calculated BMI value
print("BMI:", round(bmi, 2)) # Rounds BMI to 2 decimal places
# Function to provide feedback based on BMI
def bmi_feedback(bmi):
if bmi < 18.5:
return "You are underweight"
elif 18.5 <= bmi <= 24.9:
return "You have a healthy weight"
elif 25 <= bmi <= 29.9:
return "You are overweight"
else:
return "You are obese"
# Call the feedback function and store the result
bmi_result = bmi_feedback(bmi)
# Output the BMI category feedback
print("BMI Result:", bmi_result)
Output:
Enter your weight:58
Enter your height:1.67
BMI: 20.796729893506402
BMI Result: You have a healthy weight
Top comments (0)