+ 1
BMI problem what's wrong ?
Hello everyone, I was wondering why this code is incorrect for the BMI problem ? x=float(input("weight")) y=float(input("height")) BMI = x/(y**2) 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")
9 Respostas
+ 3
It's not necessary to add prompt(input) message in your solution.
x = float(input())
y = float(input())
+ 1
Nelson M If it runs through automated test cases it is wrong if it doesnt exactly follow the specification
+ 1
Do not put "weight" and "height" inside your input. Instead just write:
x=float(input())
y=float(input())
Everything else seems fine to me.
0
Look at the condition in the two `elif` blocks. You are supposed to check whether <BMI> was within certain range, but you instead were checking <x> to the right of logical AND operator.
elif BMI >=18.5 and x <25:
print ("Normal")
elif BMI >= 25 and x <30:
print ("Overweight")
(Edit)
Snippet is edited.
0
Oh my bad I didnt copy the good one (I modified it above):
x=float(input("weight"))
y=float(input("height"))
BMI = x/(y**2)
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")
Why it's still wrong ?
0
Simba So it's wrong to put "weight" inside the input ? How the user would know between weight or height is "x" ?
0
Nelson M as this is a code coach problem, only automated tests will run your code ^^
0
Nelson MG
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')
0
Try this code
Nelson MG do not put prompt in input .As the sololearn compiler is not supporting
But your code will work on other compilers
Thank you. đ
x=float(input())
y=float(input())
BMI = x/(y**2)
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")