+ 1

BMI calculator

Hello, could someone give me a hint. I don't understand why this code isn't working. It's working for underweight. But all codes under it are just ignored. #your code goes here height = float(input()) weight = float(input()) bmi = weight/(height/100)**2 if bmi<18.5: print("Underweight") elif bmi>=18.5 and bmi<=25.0: print("Normal") else: print("Obesity")

12th Feb 2023, 2:09 AM
Denis Durban
Denis Durban - avatar
10 Respostas
+ 6
You're welcome, Denis Durban. I have one more tip. When the test for bmi<18.5 is false, there is no need to test also for bmi>=18.5, since that will be true. Simply test elif bmi<25.
12th Feb 2023, 2:38 AM
Brian
Brian - avatar
+ 4
Check the order of inputs specified in the task. It is weight first, then height.
12th Feb 2023, 2:26 AM
Brian
Brian - avatar
+ 2
Denis Durban if this is for the Code Coach task, there are several issues to fix. Here are the ones that I see: - inputs are swapped. - BMI formula does not match the one given - BMI=25 should be in the "Overweight" category. - missing "Overweight" range
12th Feb 2023, 2:18 AM
Brian
Brian - avatar
+ 1
Hello Brian , thank you for answering me. What do you mean with inputs are swapped?
12th Feb 2023, 2:24 AM
Denis Durban
Denis Durban - avatar
+ 1
Brian code is working now. I should focus on those details. Thanks and have a nice evening/day
12th Feb 2023, 2:29 AM
Denis Durban
Denis Durban - avatar
0
Brian eeh kinda stupid mistake. Thanks
12th Feb 2023, 2:27 AM
Denis Durban
Denis Durban - avatar
0
Prueba con esto wight=int(input()) height=float(input()) x=wight/height**2 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")
12th Feb 2023, 5:23 AM
Jesus M F Vivero
Jesus M F Vivero - avatar
0
weight = float(input()) height = float(input()) bmi = weight/(height)**2 # or you can use your code but be careful when you enter the value of weight and height if bmi<18.5: print("Underweight") elif bmi>=18.5 and bmi<=25.0: print("Normal") else: print("Obesity") It works perfectly fine
13th Feb 2023, 7:57 AM
Demissew Getachew
Demissew Getachew - avatar
0
Hey Everyone...
13th Feb 2023, 4:31 PM
Sachin Jaiswara
Sachin Jaiswara - avatar
0
Make sure that the inputs being provided to the program are valid floating-point numbers. If the inputs are not valid numbers, the calculation of the BMI may result in an error or unexpected output. Check the conditions in the elif and else statements. Make sure that the conditions are expressed correctly, and that the values being compared to the BMI are correct. For example, if the elif statement is checking for a BMI between 18.5 and 25, make sure that this range is expressed correctly in the code. Make sure that the calculation of the BMI is correct. The formula for calculating the BMI is weight (in kilograms) divided by height (in meters) squared. Make sure that the height is being divided by 100 to convert it from centimeters to meters, and that the weight and height are being used correctly in the calculation. Finally, check for any syntax errors in the code, such as missing parentheses or incorrect indentation. If you continue to have trouble with the code, please provide more information, includi
13th Feb 2023, 7:11 PM
Md Rabby
Md Rabby - avatar