-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBMI
28 lines (23 loc) · 861 Bytes
/
BMI
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
def calculate_bmi(weight_kg, height_m):
'''Calculates BMI based on weight (in kilograms) and height (in meters)'''
bmi = weight_kg / (height_m ** 2)
return bmi
def classify_bmi(bmi):
""" Classifies BMI into categories (underweight, normal, overweight)."""
if bmi < 18.5:
return "Underweight"
elif 18.5 <= bmi < 24.9:
return "Normal"
else:
return "Overweight"
def main():
try:
weight = float(input("Enter your weight in kilograms: "))
height = float(input("Enter your height in meters: "))
bmi_result = calculate_bmi(weight, height)
bmi_category = classify_bmi(bmi_result)
print(f"Your BMI is {bmi_result:.2f} ({bmi_category}).")
except ValueError:
print("Invalid input. Please enter valid weight and height.")
if __name__ == "__main__":
main()