+ 1

Can someone please help me figure out what is wrong with my code in BMI calculator exercise?

The first output is right unlike the rest hight = float(input()) weight = float(input()) bmi = weight / hight ** 2 if bmi < 18.5: print("Underweight") if bmi >= 18.5 and bmi < 25: print("Normal") if bmi > 25 and bmi < 30: print("Overweight") if bmi >= 30: print("Obesity")

12th Apr 2022, 5:48 PM
aly nagaty
6 Antworten
+ 2
weight = int(input()); height = float(input()); x = weight/float(height*height); if x < 18.5: print('Underweight') if x>=18.5 and x<25: print("Normal") if x >= 25 and x < 30: print('Overweight') if x >= 30: print('Obesity') Try this one
14th Apr 2022, 5:04 PM
Om Maurya
Om Maurya - avatar
+ 1
The first input should be weight, the second height.
12th Apr 2022, 6:02 PM
Simon Sauter
Simon Sauter - avatar
+ 1
aly nagaty use elif, as shown in Prince Kumar's answer. Also there is missing logic for when BMI is exactly equal to 25 (elif bmi > 25 should be elif bmi >= 25). That mistake could be eliminated by removing unnecessary conditionals: hight = float(input()) weight = float(input()) bmi = weight / hight ** 2 if bmi < 18.5: print("Underweight") elif bmi < 25: print("Normal") elif bmi < 30: print("Overweight") else: print("Obesity")
12th Apr 2022, 6:07 PM
Brian
Brian - avatar
+ 1
aly nagaty just two mistake bro😎 your inputs are wrong weight must be taken first then height write weight first and bmi >=25 and bmi< 30, in overweight condition rest of the logics are correct👍 it will work with if statements as well
12th Apr 2022, 6:10 PM
NonStop CODING
NonStop CODING - avatar
0
The same problem bro I tried using elif instead of if
12th Apr 2022, 5:55 PM
aly nagaty
0
The message appear : Your output "Underweight" Expected output "Obesity"
12th Apr 2022, 5:57 PM
aly nagaty