0

BMI calculator bug?

Iā€™m having trouble getting my code to output anything other than underweight. Hopefully yā€™allā€™s can help me understand what I have wrong here weight = int(input()) height = float(input()) bmi = (weight / height**2) if ("bmi < 18.5"): print("Underweight") elif ("bmi >= 18.5" and "bmi < 25"): print("Normal") elif ("bmi >= 25" and "bmi < 30"): print("Overweight") else: print("Obesity")

18th Dec 2022, 3:38 AM
Alexander Brown
2 Answers
+ 6
Don't put your condition inside quotation marks. Currently you are checking if a string is true, and a nonempty string is always evaluated to true, that's why you always get underweight.
18th Dec 2022, 3:50 AM
Tibor Santa
Tibor Santa - avatar
+ 1
Thank you been wracking my brain over this for a day im glad it was a simple fix
18th Dec 2022, 4:18 AM
Alexander Brown