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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +44 -37
app.py CHANGED
@@ -1,40 +1,47 @@
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.")
 
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
+
3
+ st.title('Welcome to BMI Calculator')
4
+
5
+ weight = st.number_input("Enter your weight (in kgs)")
6
 
7
+ status = st.radio('Select your height format: ',
8
+ ('cms', 'meters', 'feet'))
9
+
10
+ if(status == 'cms'):
11
+ height = st.number_input('Centimeters')
12
+
13
+ try:
14
+ bmi = weight / ((height/100)**2)
15
+ except:
16
+ st.text("Enter some value of height")
17
+
18
+ elif(status == 'meters'):
19
+ height = st.number_input('Meters')
20
+
21
+ try:
 
 
 
 
 
 
 
22
  bmi = weight / (height ** 2)
23
+ except:
24
+ st.text("Enter some value of height")
25
+
26
+ else:
27
+ height = st.number_input('Feet')
28
+
29
+ try:
30
+ bmi = weight / (((height/3.28))**2)
31
+ except:
32
+ st.text("Enter some value of height")
33
+
34
+ if(st.button('Calculate BMI')):
35
+
36
+ st.text("Your BMI Index is {}.".format(bmi))
37
+
38
+ if(bmi < 16):
39
+ st.error("You are Extremely Underweight")
40
+ elif(bmi >= 16 and bmi < 18.5):
41
+ st.warning("You are Underweight")
42
+ elif(bmi >= 18.5 and bmi < 25):
43
+ st.success("Healthy")
44
+ elif(bmi >= 25 and bmi < 30):
45
+ st.warning("Overweight")
46
+ elif(bmi >= 30):
47
+ st.error("Extremely Overweight")