+ 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")
7 Respuestas
+ 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
+ 1
The first input should be weight, the second height.
+ 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")
+ 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
0
The same problem bro
I tried using elif instead of if
0
The message appear :
Your output "Underweight"
Expected output "Obesity"