BMI Calculator using Python | Complete Source Code
def calculate_bmi(weight, height):
"""
Calculate BMI (Body Mass Index).
Parameters:
- weight: Weight in kilograms
- height: Height in meters
Returns:
- BMI value
"""
bmi = weight / (height ** 2)
return bmi
def interpret_bmi(bmi):
"""
Interpret BMI and provide a general health category.
Parameters:
- bmi: BMI value
Returns:
- A string indicating the BMI category
"""
if bmi < 18.5:
return "Underweight"
elif 18.5 <= bmi < 24.9:
return "Normal weight"
elif 25 <= bmi < 29.9:
return "Overweight"
else:
return "Obese"
def main():
# Get user input for weight and height
weight = float(input("Enter your weight in kilograms: "))
height_cm = float(input("Enter your height in centimeters: "))
# Convert height from centimeters to meters
height_m = height_cm / 100.0
# Calculate BMI
bmi = calculate_bmi(weight, height_m)
# Interpret BMI and display the result
category = interpret_bmi(bmi)
print(f"Your BMI is: {bmi:.2f}")
print(f"You are classified as: {category}")
if __name__ == "__main__":
main()

0 Comments