Calculate BMI using Python
The following are two Python scripts that use height and weight to calculate Body Mass Index (BMI).
The following are two Python scripts that use height and weight to calculate Body Mass Index (BMI).
Metric Units
# BMI Calculator
# Get input values from the user
height = float(input("Enter your height in meters: "))
weight = float(input("Enter your weight in kilograms: "))
# Calculate the BMI
bmi = weight / (height ** 2)
# Display the BMI value
print("Your BMI is:", round(bmi, 2))
Imperial Units
# BMI Calculator (imperial units)
# Get input values from the user
height_in = float(input("Enter your height in inches: "))
weight_lbs = float(input("Enter your weight in pounds: "))
# Convert height to meters
height_m = height_in * 0.0254
# Convert weight to kilograms
weight_kg = weight_lbs / 2.205
# Calculate the BMI
bmi = weight_kg / (height_m ** 2)
# Display the BMI value
print("Your BMI is:", round(bmi, 2))