Anum15 commited on
Commit
d67c88a
·
verified ·
1 Parent(s): 5825210

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -22
app.py CHANGED
@@ -1,3 +1,5 @@
 
 
1
  def get_height_in_meters(feet, inches):
2
  total_inches = (feet * 12) + inches
3
  height_in_meters = total_inches * 0.0254
@@ -6,29 +8,24 @@ def get_height_in_meters(feet, inches):
6
  def calculate_bmi(weight, height_m):
7
  return weight / (height_m ** 2)
8
 
9
- def main():
10
- print("Welcome to BMI Converter App!")
11
-
12
- try:
13
- weight = float(input("Enter your weight in kg: "))
14
- feet = int(input("Enter your height - Feet: "))
15
- inches = int(input("Enter your height - Inches: "))
16
 
17
- height_m = get_height_in_meters(feet, inches)
18
- bmi = calculate_bmi(weight, height_m)
 
19
 
20
- print(f"\nYour BMI is: {bmi:.2f}")
 
 
21
 
22
- if bmi < 18.5:
23
- print("You are underweight.")
24
- elif 18.5 <= bmi < 24.9:
25
- print("You have a normal weight.")
26
- elif 25 <= bmi < 29.9:
27
- print("You are overweight.")
28
- else:
29
- print("You are obese.")
30
- except ValueError:
31
- print("Please enter valid numerical inputs.")
32
 
33
- if __name__ == "__main__":
34
- main()
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+
3
  def get_height_in_meters(feet, inches):
4
  total_inches = (feet * 12) + inches
5
  height_in_meters = total_inches * 0.0254
 
8
  def calculate_bmi(weight, height_m):
9
  return weight / (height_m ** 2)
10
 
11
+ # Streamlit UI
12
+ st.title("BMI Converter App")
 
 
 
 
 
13
 
14
+ weight = st.number_input("Enter your weight (kg):", min_value=1.0, format="%.2f")
15
+ feet = st.number_input("Enter your height - Feet:", min_value=0, max_value=8, step=1)
16
+ inches = st.number_input("Enter your height - Inches:", min_value=0, max_value=11, step=1)
17
 
18
+ if st.button("Calculate BMI"):
19
+ height_m = get_height_in_meters(feet, inches)
20
+ bmi = calculate_bmi(weight, height_m)
21
 
22
+ st.write(f"### Your BMI is: {bmi:.2f}")
 
 
 
 
 
 
 
 
 
23
 
24
+ if bmi < 18.5:
25
+ st.warning("You are underweight.")
26
+ elif 18.5 <= bmi < 24.9:
27
+ st.success("You have a normal weight.")
28
+ elif 25 <= bmi < 29.9:
29
+ st.info("You are overweight.")
30
+ else:
31
+ st.error("You are obese.")