+ 1

BMI calculator

This is the code I wrote for bmi calculator but something seems to be the problem for the test cases 4 and 5. Can someone please help me with it?? weight= float(input()) height= float(input()) x=(weight)/(float(height ** 2)) if x<=18.5: print("Underweight") elif ((x>=18.6) and (x<25.0)): print ("Normal weight") elif x<=30.0: print("Overweight") else : print("Obesity")

27th Jul 2021, 7:25 PM
Shreya Shivalkar
Shreya Shivalkar - avatar
4 Respostas
0
It's should be Normal not Normal weight print("Normal")
28th Jul 2021, 1:06 AM
Simba
Simba - avatar
+ 1
Thank you soo much Simba .. One change and it's done!
28th Jul 2021, 3:04 AM
Shreya Shivalkar
Shreya Shivalkar - avatar
0
Not sure if this is the problem, but you shouldn't be using x >= 18.6. All you need to do is use x > 18.5, you're skipping 0.1 of the number range. Also not sure if this is a problem, but you use <= for pretty much all the less than comparisons, yet you don't for the case of 25.0, why?
27th Jul 2021, 7:40 PM
BootInk
BootInk - avatar
0
You know there are many numbers between 18.5 and 18.6, right? All those numbers should be Normal Weight, but they don't match your condition, but they match the next condition (Overweight) Also, I think 25.0 should be Normal Weight So, the conditions should be: x<=18.5 x<=25.0 (you don't have to worry to check if x>18.5, you already know it because of the way if/else works) x<=30.0 P.S.: x>a and x<b can be written as a<x<b
27th Jul 2021, 11:17 PM
Angelo
Angelo - avatar