File size: 1,079 Bytes
f938487
 
b07ebc5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st

st.title("BMI Calculator")

# Input weight (kg) and height (cm) as integers via text input
weight_input = st.text_input("Enter your weight (kg):", value="")
height_input = st.text_input("Enter your height (cm):", value="")

# Validate inputs and calculate BMI
if st.button("Calculate BMI"):
    try:
        weight = int(weight_input)
        height = int(height_input)
        if weight <= 0 or height <= 0:
            st.error("Please enter positive integers for weight and height.")
        else:
            height_in_m = height / 100  # Convert cm to meters
            bmi = weight / (height_in_m ** 2)
            st.success(f"Your BMI: {bmi:.2f}")

            # BMI Categories
            if bmi < 18.5:
                st.warning("Underweight")
            elif 18.5 <= bmi < 25:
                st.success("Normal weight")
            elif 25 <= bmi < 30:
                st.warning("Overweight")
            else:
                st.error("Obese")
    except ValueError:
        st.error("Please enter valid integer values for both fields.")