+ 2
BMI calculator: Hello, can someone help me identify why my BMI calculator is not passing the test?
#your code goes here h=(float(input()))**2 w=float(input()) b=w/h if b<18.5: print("Underweight") elif b>=18.5 and b<25: print("Normal") elif b>=25 and b<30: print ("Overweight") elif b>=30: print ("Obesity") else: pass
6 Respuestas
+ 6
First w then h
+ 2
Because, test cases are handled by the compiler itself. So, inputs order need to be same as programmed
+ 1
h=(float(input()))**2
w=float(input())
b=w/h
if b < 18.5:
print("Underweight")
elif b < 25:
print("Normal")
elif b < 30:
print ("Overweight")
else:
print ("Obesity")
I would change the logic to above the and is not necessary. The code will only step to the first true test in the if conditional
+ 1
Simba , thank you
0
Simba, why does the order matter? When I used w first, it worked but in jupyter notebook, h first works perfectly, too. Thank you
0
William Owens, thank you