+ 1

What's wrong with my code?

It's about BMI calculator. weight=int(input()) height=float(input()) B=weight/(height*height) print(B) 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")

19th Jun 2021, 2:23 PM
Gareth Batman
3 Respuestas
+ 12
weight=int(input()) height=float(input()) B=weight/(height*height) #print(B) 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")
19th Jun 2021, 2:31 PM
Simba
Simba - avatar
+ 5
Gareth Batman , Simba , it looks like both codes have still an issue, if B will be 30: this is due to the definition of the conditionals which excludes the number of 30. if ... B < 30: .... elif ...B > 30: .... may be it does not cause an error with test cases, if the input values do not result to the value of 30 for the BMI.
19th Jun 2021, 3:20 PM
Lothar
Lothar - avatar
+ 3
by the way, what do you think should print your code if BMI is 30?
19th Jun 2021, 3:16 PM
The future is now thanks to science
The future is now thanks to science - avatar