0

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.

13th Feb 2021, 2:37 PM
Kushal Acharya
6 odpowiedzi
+ 4
Kushal 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'
13th Feb 2021, 3:59 PM
noteve
noteve - avatar
+ 2
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")
13th Feb 2021, 3:03 PM
K.S.S. Karunarathne
K.S.S. Karunarathne - avatar
+ 1
Thanks Cyan👍
13th Feb 2021, 4:05 PM
Kushal Acharya
0
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.
13th Feb 2021, 3:39 PM
Kushal Acharya
0
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')
14th Feb 2021, 2:41 AM
❤️😍Prerana😍❤️
❤️😍Prerana😍❤️ - avatar
0
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')
21st Feb 2021, 4:55 PM
RXRX
RXRX - avatar