+ 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")

26th Mar 2021, 12:17 PM
Nelson MG
Nelson MG - avatar
9 Respostas
+ 3
It's not necessary to add prompt(input) message in your solution. x = float(input()) y = float(input())
26th Mar 2021, 12:34 PM
Simba
Simba - avatar
+ 1
Nelson M If it runs through automated test cases it is wrong if it doesnt exactly follow the specification
26th Mar 2021, 2:31 PM
John Doe
+ 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.
28th Mar 2021, 12:59 PM
Ava
Ava - avatar
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.
26th Mar 2021, 12:21 PM
Ipang
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 ?
26th Mar 2021, 12:24 PM
Nelson MG
Nelson MG - avatar
0
Simba So it's wrong to put "weight" inside the input ? How the user would know between weight or height is "x" ?
26th Mar 2021, 12:42 PM
Nelson MG
Nelson MG - avatar
0
Nelson M as this is a code coach problem, only automated tests will run your code ^^
26th Mar 2021, 3:58 PM
visph
visph - avatar
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')
27th Mar 2021, 11:40 PM
â€ïžđŸ˜PreranađŸ˜â€ïž
â€ïžđŸ˜PreranađŸ˜â€ïž - avatar
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")
28th Mar 2021, 9:23 AM
Dasari Navyateja
Dasari Navyateja - avatar