Body Mass Index (BMI) is a measurement that helps determine if a person has a healthy body weight for their height. The formula to calculate BMI is:
BMI = weight (kg) / (height (m) ^ 2)
Here’s a simple Python program to calculate BMI based on user input for weight and height:
1. Python Program
2. Explanation
The program includes the following functions:
- calculate_bmi(weight, height): Computes the BMI using the weight and height provided.
- get_bmi_category(bmi): Determines the BMI category based on the BMI value.
- main(): Handles user input, performs BMI calculation, and prints the result along with the BMI category.
3. Running the Program
To run the BMI calculator:
- Copy and paste the code into a Python script file (e.g.,
bmi_calculator.py
). - Execute the script using Python:
python bmi_calculator.py
- Follow the prompts to enter weight and height to get your BMI and category.
4. Summary
This BMI calculator program in Python is a simple and effective way to compute and categorize Body Mass Index based on user input. It provides clear feedback and handles invalid input gracefully.