-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathPython_BMI_Calculator.py
More file actions
31 lines (26 loc) · 986 Bytes
/
Python_BMI_Calculator.py
File metadata and controls
31 lines (26 loc) · 986 Bytes
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
def calculate_bmi(weight_kg, height_m):
bmi = weight_kg / (height_m ** 2)
return bmi
def interpret_bmi(bmi):
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"
if __name__ == "__main__":
print("Welcome to the BMI Calculator!")
try:
weight_kg = float(input("Enter your weight in kilograms: "))
height_m = float(input("Enter your height in meters: "))
if weight_kg <= 0 or height_m <= 0:
print("Invalid input. Weight and height must be positive numbers.")
else:
bmi = calculate_bmi(weight_kg, height_m)
bmi_category = interpret_bmi(bmi)
print(f"Your BMI is: {bmi:.2f}")
print(f"Category: {bmi_category}")
except ValueError:
print("Invalid input. Please enter valid numbers for weight and height.")