Ashar086 commited on
Commit
f2ea00e
·
verified ·
1 Parent(s): 6ae128f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -21
app.py CHANGED
@@ -1,27 +1,40 @@
1
-
2
  import streamlit as st
3
- st.title("BMI Calculator")
4
 
5
- weight = st.number_input("Enter your weight (kg):", min_value=1.0, format="%.2f")
 
 
 
 
 
 
6
 
7
- height_unit = st.selectbox("Select height unit:", ["Centimeters", "Meters", "Feet"])
8
- height = st.number_input("Enter your height:", min_value=1.0, format="%.2f")
9
- if height_unit == "Centimeters":
10
- height = height / 100
11
- elif height_unit == "Feet":
12
- height = height * 0.3048
 
 
 
 
13
 
14
- if height > 0:
15
- bmi = weight / (height ** 2)
16
- st.write(f"### Your BMI: {bmi:.2f}")
 
 
17
 
18
- if bmi < 18.5:
19
- st.warning("You are underweight.")
20
- elif 18.5 <= bmi < 24.9:
21
- st.success("You have a normal weight.")
22
- elif 25 <= bmi < 29.9:
23
- st.warning("You are overweight.")
 
 
 
 
 
24
  else:
25
- st.error("You are in the obese category.")
26
- else:
27
- st.error("Please enter a valid height.")
 
 
1
  import streamlit as st
 
2
 
3
+ st.title("BMI Calculator App")
4
+
5
+ # Input weight
6
+ weight = st.number_input("Enter your weight (in kgs)", min_value=0.0, step=0.1)
7
+
8
+ # Select height format
9
+ status = st.radio('Select your height format:', ('cms', 'meters', 'feet'))
10
 
11
+ # Input height based on selection
12
+ height = 0
13
+ if status == 'cms':
14
+ height = st.number_input('Enter height in Centimeters', min_value=0.0, step=0.1)
15
+ height /= 100 # Convert to meters
16
+ elif status == 'meters':
17
+ height = st.number_input('Enter height in Meters', min_value=0.0, step=0.01)
18
+ elif status == 'feet':
19
+ height = st.number_input('Enter height in Feet', min_value=0.0, step=0.1)
20
+ height /= 3.281 # Convert to meters
21
 
22
+ # BMI Calculation and Display
23
+ if st.button('Calculate BMI'):
24
+ if height > 0:
25
+ bmi = weight / (height ** 2)
26
+ st.text(f"Your BMI Index is {bmi:.2f}.")
27
 
28
+ # Categorizing BMI
29
+ if bmi < 16:
30
+ st.error("You are Extremely Underweight")
31
+ elif 16 <= bmi < 18.5:
32
+ st.warning("You are Underweight")
33
+ elif 18.5 <= bmi < 25:
34
+ st.success("You are Healthy")
35
+ elif 25 <= bmi < 30:
36
+ st.warning("You are Overweight")
37
+ else:
38
+ st.error("You are Extremely Overweight")
39
  else:
40
+ st.error("Please enter a valid height greater than 0.")