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()