From 43b19eedf3a79dc4849de9820d50f3e32c8b88c0 Mon Sep 17 00:00:00 2001 From: astitva3107 <61946304+astitva3107@users.noreply.github.com> Date: Fri, 19 Jan 2024 18:26:05 +0530 Subject: [PATCH] Update BMI CALCULATER --- BMI CALCULATER | 64 +++++++++++++++++++++++++++----------------------- 1 file changed, 34 insertions(+), 30 deletions(-) diff --git a/BMI CALCULATER b/BMI CALCULATER index cf44e69..b06d50b 100644 --- a/BMI CALCULATER +++ b/BMI CALCULATER @@ -1,31 +1,35 @@ -filter_none -edit -play_arrow +def calculate_bmi(height, weight): + bmi = weight / (height ** 2) + return bmi -brightness_4 -#Python program to illustrate -# how to calculate BMI -def BMI(height, weight): - bmi = weight/(height**2) - return bmi - -# Driver code -height = 1.79832 -weight = 70 - -# calling the BMI function -bmi = BMI(height, weight) -print("The BMI is", format(bmi), "so ", end='') - -# Conditions to find out BMI category -if (bmi < 18.5): - print("underweight") - -elif ( bmi >= 18.5 and bmi < 24.9): - print("Healthy") - -elif ( bmi >= 24.9 and bmi < 30): - print("overweight") - -elif ( bmi >=30): - print("Suffering from Obesity") +def categorize_bmi(bmi_value): + if bmi_value < 18.5: + return "Underweight" + elif 18.5 <= bmi_value < 24.9: + return "Healthy" + elif 24.9 <= bmi_value < 30: + return "Overweight" + elif bmi_value >= 30: + return "Suffering from Obesity" + else: + return "Invalid BMI" + +def main(): + try: + # Get user input for height and weight + height = float(input("Enter your height in meters: ")) + weight = float(input("Enter your weight in kilograms: ")) + except ValueError: + print("Invalid input. Please enter numeric values for height and weight.") + return + + # Calculate BMI + bmi = calculate_bmi(height, weight) + print("Your BMI is:", format(bmi, ".2f")) + + # Categorize BMI + category = categorize_bmi(bmi) + print("You are", category) + +if __name__ == "__main__": + main()