+ 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")
4 Answers
0
It's should be Normal not Normal weight
print("Normal")
+ 1
Thank you soo much Simba .. One change and it's done!
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?
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