# Python bmi challange

Unable to find error in my code. My code is weight=int(input()) height=float(input()) bmi=weight/(height**2) if bmi<18.5: print("Underweight") elif bmi>=18.5 or bmi<25: print("Normal") elif bmi>=25 or bmi<30: print("Overweight") elif bmi>=30: print("Obesity") But somehow answer 2 is incorrect which is I am not able to find why? Plz help.

2/13/2021 2:37:02 PM

Kushal Acharya6 Answers

New AnswerKushal Acharya Though you already got an answer, I will try to clarify the problem. That is because you used "or" logical operator on your conditions. For example if bmi is 35, it will print "Normal" instead because of the condition "elif bmi >=25 or bmi < 35" and the bmi >= 25 is True, when it is supposed to be "Obesity". Remember that when using 'or', if either of the condition is True, then the whole condition will become True. TO SOLVE: ---> Just use 'and' instead of 'or'

Kushal Acharya Try this one weight = float(input("")) height = float(input("")) bmi = weight / (height ** 2) if bmi < 18.5: print("Underweight") elif bmi == 18.5 or bmi > 18.5 and bmi < 25.0: print("Normal") elif bmi == 25.0 or bmi > 25.0 and bmi < 30.0: print("Overweight") else: print("Obesity")

Thanks K.S.S. KARUNARATHNE for the solution but please point out where I was doing mistake I it was for taking float values for both height and weight or == that I was missing.

You can try this #your code goes here weight = int(input()); height = float(input()); bmi = weight/float(height*height); if bmi<18.5: print('Underweight') elif bmi>=18.5 and bmi<25: print("Normal") elif bmi>=25 and bmi<30: print('Overweight') else: print('Obesity')

bmi = float(input())/float(input())**2 if bmi<18.5:print('Underweight') elif 25>bmi>=18.5:print('Normal') elif 30>bmi>=25:print('OverWeight') elif bmi>=30:print('Obesity')