File size: 1,148 Bytes
95ad8c0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
40
41
42
43
44
45
46
47
48
49
50
import streamlit as st

def calculate_bmi(weight, height):
  """Calculates the Body Mass Index (BMI).

  Args:
    weight: Weight in kilograms.
    height: Height in meters.

  Returns:
    The calculated BMI.
  """
  return weight / (height * height)

def get_bmi_category(bmi):
  """Determines the BMI category based on the calculated value.

  Args:
    bmi: The calculated Body Mass Index.

  Returns:
    The corresponding BMI category.
  """
  if bmi < 18.5:
    return "Underweight"
  elif 18.5 <= bmi < 25:
    return "Normal"
  elif 25 <= bmi < 30:
    return "Overweight"
  else:
    return "Obese"

def main():
  st.title("BMI Calculator")

  weight = st.number_input("Enter your weight (kg)", min_value=0.0)
  height = st.number_input("Enter your height (m)", min_value=0.0)

  if st.button("Calculate BMI"):
    if weight > 0 and height > 0:
      bmi = calculate_bmi(weight, height)
      category = get_bmi_category(bmi)

      st.success(f"Your BMI is: {bmi:.2f}")
      st.info(f"You are in the '{category}' category.")
    else:
      st.warning("Please enter valid weight and height values.")

if __name__ == "__main__":
  main()