-
-
Notifications
You must be signed in to change notification settings - Fork 382
Expand file tree
/
Copy pathBMI.PY
More file actions
39 lines (34 loc) · 1.05 KB
/
BMI.PY
File metadata and controls
39 lines (34 loc) · 1.05 KB
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
29
30
31
32
33
34
35
36
37
38
39
def calculate_bmi(weight_kg, height_cm):
"""
Calculate BMI given weight in kilograms and height in centimeters.
BMI formula: weight (kg) / (height (m) ** 2)
"""
height_m = height_cm / 100 # convert cm to meters
bmi = weight_kg / (height_m ** 2)
return round(bmi, 2) # rounded to 2 decimal places
def categorize_bmi(bmi):
"""
Categorize BMI according to WHO standards.
"""
if bmi < 18.5:
return "Underweight"
elif 18.5 <= bmi < 24.9:
return "Normal weight"
elif 25 <= bmi < 29.9:
return "Overweight"
else:
return "Obese"
def main():
# User input
try:
weight = float(input("Enter your weight in kg: "))
height = float(input("Enter your height in cm: "))
bmi = calculate_bmi(weight, height)
category = categorize_bmi(bmi)
print(f"
Your BMI is: {bmi}")
print(f"Category: {category}")
except ValueError:
print("Invalid input! Please enter numeric values for weight and height.")
if __name__ == "__main__":
main()