Stuck with BMI calculator test4 | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Stuck with BMI calculator test4

Not sure what is wrong. I checked it in python compiler and it all works. A but puzzled with this. Anybody any suggestions about my code underneath. Many thanks in advance kilograms = float(input()) height = float(input()) bmi = kilograms / height**2 status = bmi if(0<=status<18.5): print("Underweight") elif(18.5<=status<24.9): print("Normal") elif(25.0<=status<29.9): print("Overweight") elif(status >30.0): print("Obesity")

12th Apr 2022, 8:29 PM
Christopher Egan
Christopher Egan - avatar
2 Answers
+ 4
You don't have to use .9 or something for Normal and Overweight. Less than 25 and less than 30 are the correct answers. You can easily simplify your answer with elif statements. if bmi < 18.5: print("Underweight") elif bmi < 25: print("Normal") elif bmi < 30: print("Overweight") else: print("Obesity") Elif aren't only if statements. It runs only if the previous if or elif block verification is false to move on to its own block, which means for example that a float that is greater than 18.5 (if statement) is certainly between 18.5 and 25 if it is less than 25. (first elif statement)
12th Apr 2022, 8:39 PM
Orisa
Orisa - avatar
+ 1
Thanks very much Orisa and Potro for your answers they worked. I guess I over thought this one
12th Apr 2022, 8:49 PM
Christopher Egan
Christopher Egan - avatar