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?
2/5/2021 2:15:59 PM
Thuan Le
34 Answers
New Answer#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
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")
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")
i did that in my other attempts, but it still didnt work, i copied abhays code and it worked right away lol
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
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")
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
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')
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
∆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?