+ 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")
2 ответов
+ 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)
+ 1
Thanks very much Orisa and Potro for your answers they worked. I guess I over thought this one