Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bmi_categories = {0:"Severely Underweight",
- 1:"Underweight",
- 2:"Normal",
- 3:"Overweight",
- 4:"Moderately Obese",
- 5:"Severely Obese",
- 6:"Morbidly Obese"}
- STD_BMI_VALUES = (15, 18, 18.5, 25, 30, 35, 40, 60)
- def get_bmi_category(bmi):
- for i in range(len(STD_BMI_VALUES)-1):
- mn, mx = STD_BMI_VALUES[i], STD_BMI_VALUES[i+1]
- if (bmi >= mn and bmi < mx): bmi = i
- return bmi_categories.get(bmi, "Uncategorized")
- std = {"Height":(1.4, 2, 'meters'),"Weight":(35, 120, 'Kg')}
- def get_user_input(_type, n='E'):
- mn, mx, unit = std[_type]
- try:
- _input = float(input(f"\n{n}nter your {_type} in {unit}: "))
- if not (_input >= mn and _input <= mx): raise Warning()
- return _input
- except Exception as e:
- print(("Invalid Input.", f"{_type} out of acceptable range.")[isinstance(e, Warning)])
- return get_user_input(_type, 'Please re-e')
- weight, height = get_user_input('Weight'), get_user_input('Height')
- rating = get_bmi_category(round(weight/height**2, 1))
- print(f"Based on your weight of {weight} Kg, and your height of {height} meters, your BMI rating is {rating}")
Add Comment
Please, Sign In to add comment