+ 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

26th Feb 2022, 2:21 AM
Emmanuel Owusu oppong
Emmanuel Owusu oppong - avatar
6 Answers
+ 6
First w then h
26th Feb 2022, 2:30 AM
Simba
Simba - avatar
+ 2
Because, test cases are handled by the compiler itself. So, inputs order need to be same as programmed
26th Feb 2022, 4:18 PM
Simba
Simba - avatar
+ 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
26th Feb 2022, 2:37 AM
William Owens
William Owens - avatar
+ 1
Simba , thank you
26th Feb 2022, 4:23 PM
Emmanuel Owusu oppong
Emmanuel Owusu oppong - avatar
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
26th Feb 2022, 3:59 PM
Emmanuel Owusu oppong
Emmanuel Owusu oppong - avatar
0
William Owens, thank you
26th Feb 2022, 3:59 PM
Emmanuel Owusu oppong
Emmanuel Owusu oppong - avatar