 Bmi calculator | Sololearn: Learn to code for FREE!

+5

# Bmi calculator

height = float(input()) weight = float(input()) bmi = weight/(height**2) if (bmi < 18.5): print("Underweight") elif ((bmi>= 18.5) and (bmi< 25)): print("Normal") elif ((bmi>= 25) and (bmi< 30)): print("Overweight") elif (bmi > 30): print("Obesity") i passed test 1 but for test 2 it says expected output is obesity but it says my code has output underweight?

+16

#your code goes here weight = float(input()) height = float(input()) bmi = weight / (height ** 2) if bmi < 18.5: print('Underweight') elif bmi >= 18.5 and bmi < 25: print('Normal') elif bmi >= 25 and bmi < 30: print('Overweight') elif bmi >= 30: print('Obesity') # Your code may have some bugs , try out my code and happy coding journey

+8

"Ben Steven" you can test in the compiler

+6

The last line Yours 30 > bmi Correct 30 >= bmi

+5

Try this one please 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")

+3

converted every single number still wont let me pass test 2

+3

i did that in my other attempts, but it still didnt work, i copied abhays code and it worked right away lol

+3

weight = float(input()) height = float(input()) BMI = weight / (height**2) if BMI < 18.5: print("Underweight") elif BMI >= 18.5 and BMI<25: print("Normal") elif BMI >= 25 and BMI < 30: print("Overweight") elif BMI > 30 : print("Obesity")

+3

+2

This may help w = int (input()) h = float (input()) b = w/h**2 if b < 18.5: print("Underweight") elif b >= 18.5 and b < 25: print("Normal") elif b >= 25 and b < 30: print("Overweight") else: print("Obesity") # You should fill the input box with weight & height at the same time # e.g # 89 (weight) # 1.87 (height) # submit

+2

Because weight is in int in the quiz

+2

My code is shorter: weight = int(input()) height = float(input()) bmi = weight / (height * height) if bmi < 18.5: print("Underweight") elif bmi < 25: print("Normal") elif bmi < 30: print("Overweight") else: print("Obesity")

+1

Look at the last line of the code In yours it will return obesity if it's bigger than 30. In mine it will return obesity if it's 30 as well

+1

Did you converted those numners into float.

+1

+1

thats bro but i hardly see any difference with yours and mine, how come mine is wrong?

+1

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')

+1

You should fill weight and height at the same time in the same input box e.g 85 --> weight 1.80 --> height if you just write weight, you will have EOF Erro

+1

For the Obesity part, remove elif and put else.. it will be much easier.

+1

∆BH∆Y Thuan Le The order that the input’s are listed seems to matter. Initially I had: height = float(input()) weight = float(input()) bmi = weight/(height**2) #note, height is on top. Test case failed. I then switched weight to the first line and it worked! # I played around with making a prompt for the user weight = float(int( “Enter your weight”)) but it didn’t work like I wanted and gave up. Thoughts on adding a height & weight prompt?