Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def get_float(prompt):
- while True:
- s = input("\n" + prompt)
- try:
- return s, float(s) # return the original string AND the float value
- except:
- print("Invalid input. Please re-enter")
- while True:
- height_str, height_float = get_float("Enter your height in metres: ")
- if 1.35 < height_float < 2.1:
- break
- print("Height out of acceptable range. Please re-enter")
- while True:
- weight_str, weight_float = get_float("Enter your weight in Kg: ")
- if 35 < weight_float < 120:
- break
- print("Weight out of acceptable range. Please re-enter")
- bmi = weight_float / (height_float ** 2)
- cats = [-1, "severely underweight", 15, "underweight", 18.5, "normal", 25, "overweight",
- 30, "moderately obese", 35, "severely obese", 40, "morbidly obese"]
- for x in range(0, len(cats), 2):
- if bmi >= cats[x]:
- text = cats[x+1]
- print(f"\nBased on your weight of {weight_str} Kg, and your height of {height_str} metres, your BMI rating is {text}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement