From dbba6c6ae43125ea8cb46d8b32d91f2da0ebc65a Mon Sep 17 00:00:00 2001 From: Sumith Das <129795841+Sumith540@users.noreply.github.com> Date: Mon, 7 Oct 2024 20:28:05 +0530 Subject: [PATCH] Created BMI calculator MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I have added a BMI calculator using python... How to Use the Program: Input: The program prompts the user to enter their weight in kilograms and height in meters. Calculation: It calculates the BMI using the formula: BMI = weight (kg) ( height (m) ) 2 BMI= (height (m)) 2 weight (kg) ​ Classification: Based on the BMI value, it categorizes the user into one of four categories: Underweight, Normal weight, Overweight, or Obesity. Output: Finally, it displays the calculated BMI and the corresponding classification. --- BMI calculator | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 BMI calculator diff --git a/BMI calculator b/BMI calculator new file mode 100644 index 00000000..c7ebe1a9 --- /dev/null +++ b/BMI calculator @@ -0,0 +1,35 @@ +def calculate_bmi(weight, height): + """Calculate and return the BMI.""" + bmi = weight / (height ** 2) + return bmi + +def get_bmi_category(bmi): + """Determine the BMI category based on the BMI value.""" + if bmi < 18.5: + return "Underweight" + elif 18.5 <= bmi < 24.9: + return "Normal weight" + elif 25 <= bmi < 29.9: + return "Overweight" + else: + return "Obesity" + +def main(): + print("Welcome to the BMI Calculator!") + + # Get user input for weight and height + weight = float(input("Enter your weight in kilograms: ")) + height = float(input("Enter your height in meters: ")) + + # Calculate BMI + bmi = calculate_bmi(weight, height) + + # Get BMI category + category = get_bmi_category(bmi) + + # Display the result + print(f"Your BMI is: {bmi:.2f}") + print(f"You are classified as: {category}") + +if __name__ == "__main__": + main()