+ 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")
3 Antworten
+ 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")
+ 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.
+ 3
by the way, what do you think should print your code if BMI is 30?