Certainly! Below is a simple Python program that calculates the Body Mass Index (BMI) based on user input for weight and height, and then categorizes the result.
def calculate_bmi(weight, height):
return weight / (height ** 2)
def get_bmi_category(bmi):
if bmi < 18.5:
return "Underweight"
elif 18.5 <= bmi < 25:
return "Normal weight"
elif 25 <= bmi < 30:
return "Overweight"
else:
return "Obese"
def main():
print("Welcome to the BMI Calculator")
# Get user input for weight and height
weight = float(input("Please enter your weight in kilograms: "))
height = float(input("Please enter your height in meters: "))
# Calculate BMI
bmi = calculate_bmi(weight, height)
# Determine the BMI category
category = get_bmi_category(bmi)
# Print the results
print(f"Your BMI is: {bmi:.2f}")
print(f"You are classified as: {category}")
if __name__ == "__main__":
main()
How to Use the Program
- Copy the code into a Python environment (like a text editor, or an IDE such as PyCharm or Jupyter Notebook).
- Run the program.
- Follow the prompts to enter your weight in kilograms and height in meters.
- The program will calculate your BMI and provide you with a classification based on the BMI value.
Notes
- Ensure that you input valid numerical values for weight and height.
- The BMI formula is defined as \( \text{BMI} = \frac{\text{weight}}{\text{height}^2} \).