|
1 | | -filter_none |
2 | | -edit |
3 | | -play_arrow |
| 1 | +def calculate_bmi(height, weight): |
| 2 | + bmi = weight / (height ** 2) |
| 3 | + return bmi |
4 | 4 |
|
5 | | -brightness_4 |
6 | | -#Python program to illustrate |
7 | | -# how to calculate BMI |
8 | | -def BMI(height, weight): |
9 | | - bmi = weight/(height**2) |
10 | | - return bmi |
11 | | - |
12 | | -# Driver code |
13 | | -height = 1.79832 |
14 | | -weight = 70 |
15 | | - |
16 | | -# calling the BMI function |
17 | | -bmi = BMI(height, weight) |
18 | | -print("The BMI is", format(bmi), "so ", end='') |
19 | | - |
20 | | -# Conditions to find out BMI category |
21 | | -if (bmi < 18.5): |
22 | | - print("underweight") |
23 | | - |
24 | | -elif ( bmi >= 18.5 and bmi < 24.9): |
25 | | - print("Healthy") |
26 | | - |
27 | | -elif ( bmi >= 24.9 and bmi < 30): |
28 | | - print("overweight") |
29 | | - |
30 | | -elif ( bmi >=30): |
31 | | - print("Suffering from Obesity") |
| 5 | +def categorize_bmi(bmi_value): |
| 6 | + if bmi_value < 18.5: |
| 7 | + return "Underweight" |
| 8 | + elif 18.5 <= bmi_value < 24.9: |
| 9 | + return "Healthy" |
| 10 | + elif 24.9 <= bmi_value < 30: |
| 11 | + return "Overweight" |
| 12 | + elif bmi_value >= 30: |
| 13 | + return "Suffering from Obesity" |
| 14 | + else: |
| 15 | + return "Invalid BMI" |
| 16 | + |
| 17 | +def main(): |
| 18 | + try: |
| 19 | + # Get user input for height and weight |
| 20 | + height = float(input("Enter your height in meters: ")) |
| 21 | + weight = float(input("Enter your weight in kilograms: ")) |
| 22 | + except ValueError: |
| 23 | + print("Invalid input. Please enter numeric values for height and weight.") |
| 24 | + return |
| 25 | + |
| 26 | + # Calculate BMI |
| 27 | + bmi = calculate_bmi(height, weight) |
| 28 | + print("Your BMI is:", format(bmi, ".2f")) |
| 29 | + |
| 30 | + # Categorize BMI |
| 31 | + category = categorize_bmi(bmi) |
| 32 | + print("You are", category) |
| 33 | + |
| 34 | +if __name__ == "__main__": |
| 35 | + main() |
0 commit comments