+ 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?

5th Feb 2021, 2:15 PM
Thuan Le
32 Respostas
+ 8
"Ben Steven" you can test in the compiler
7th Feb 2021, 12:05 PM
Melekte Petros
Melekte Petros - avatar
+ 6
The last line Yours 30 > bmi Correct 30 >= bmi
5th Feb 2021, 2:37 PM
K.S.S. Karunarathne
K.S.S. Karunarathne - avatar
+ 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")
5th Feb 2021, 2:16 PM
K.S.S. Karunarathne
K.S.S. Karunarathne - avatar
+ 4
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")
7th Feb 2021, 7:49 AM
Saurabh Kumar Mishra
Saurabh Kumar Mishra - avatar
+ 3
converted every single number still wont let me pass test 2
5th Feb 2021, 2:33 PM
Thuan Le
+ 3
i did that in my other attempts, but it still didnt work, i copied abhays code and it worked right away lol
5th Feb 2021, 2:38 PM
Thuan Le
+ 3
This is the code
7th Feb 2021, 7:49 AM
Saurabh Kumar Mishra
Saurabh Kumar Mishra - avatar
+ 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
6th Feb 2021, 12:29 AM
Abdadiam Aljrushi
Abdadiam Aljrushi - avatar
+ 2
Because weight is in int in the quiz
6th Feb 2021, 9:20 AM
Deepshikha Shivhare
Deepshikha Shivhare - avatar
+ 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")
11th Mar 2021, 2:28 PM
Luiza
Luiza - avatar
+ 2
šŸ‘
19th Aug 2021, 7:12 AM
Sariga.S
+ 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
5th Feb 2021, 2:20 PM
K.S.S. Karunarathne
K.S.S. Karunarathne - avatar
+ 1
Did you converted those numners into float.
5th Feb 2021, 2:26 PM
K.S.S. Karunarathne
K.S.S. Karunarathne - avatar
+ 1
same thing brother
5th Feb 2021, 2:32 PM
Thuan Le
+ 1
thats bro but i hardly see any difference with yours and mine, how come mine is wrong?
5th Feb 2021, 2:36 PM
Thuan Le
+ 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')
5th Feb 2021, 3:16 PM
Motuncoded
Motuncoded - avatar
+ 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
6th Feb 2021, 12:22 AM
Abdadiam Aljrushi
Abdadiam Aljrushi - avatar
+ 1
For the Obesity part, remove elif and put else.. it will be much easier.
6th Feb 2021, 4:36 PM
Sojith Sunny
Sojith Sunny - avatar
+ 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?
28th Feb 2021, 4:29 PM
Kaiaiak
Kaiaiak - avatar
+ 1
BMI calculation with BMI values 'BMI Calculator' weight=int(input()) height=float(input()) bmi=weight/float(height**2) if bmi<18: print("Underweight") print(float(bmi)) elif bmi>=18 and bmi<25: print("Normal") print(float(bmi)) elif bmi>=25 and bmi<30: print("Overweight") print(float(bmi)) elif bmi>=30: print("Obesity, ") print(float(bmi))
3rd Mar 2021, 6:38 PM
Lok Soni
Lok Soni - avatar