-
Notifications
You must be signed in to change notification settings - Fork 472
/
BMI calculator
35 lines (28 loc) · 904 Bytes
/
BMI calculator
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
def calculate_bmi(weight, height):
"""Calculate and return the BMI."""
bmi = weight / (height ** 2)
return bmi
def get_bmi_category(bmi):
"""Determine the BMI category based on the BMI value."""
if bmi < 18.5:
return "Underweight"
elif 18.5 <= bmi < 24.9:
return "Normal weight"
elif 25 <= bmi < 29.9:
return "Overweight"
else:
return "Obesity"
def main():
print("Welcome to the BMI Calculator!")
# Get user input for weight and height
weight = float(input("Enter your weight in kilograms: "))
height = float(input("Enter your height in meters: "))
# Calculate BMI
bmi = calculate_bmi(weight, height)
# Get BMI category
category = get_bmi_category(bmi)
# Display the result
print(f"Your BMI is: {bmi:.2f}")
print(f"You are classified as: {category}")
if __name__ == "__main__":
main()