+ 1

Can someone please explain why this isn't working?

Can some pls explain why this code isn't working? I know I am an amature so it may have a lot of problems lol But why isn't it working? https://code.sololearn.com/clPipht2D9Wz/?ref=app

4th Jan 2022, 2:46 PM
Preeyansh Tibrewal
Preeyansh Tibrewal - avatar
7 Answers
+ 4
You must specify what you are comparing in order to complete the boolean expression. elif user_bmi >= 18.5 or < 25: Should be: elif user_bmi >= 18.5 or user_bmi < 25: Also, there is no need to check if user_bmi >= 18.5 since at this point in the logic you already established that it is not < 18.5. Now you only need to check if it is < 25. if user_bmi < 18.5: print("Underweight") elif user_bmi < 25: print("Normal") The same improvement applies to the 30 threshold. The final elif should be a simple else.
4th Jan 2022, 3:46 PM
Brian
Brian - avatar
+ 7
Preeyansh Tibrewal , there is also a issue with the logical operator in the conditional statements. we can not use *or* to build this logic, it needs to be *and* . to reduce the confusion, here is the complete code: weight = int(input()) height = float(input()) user_bmi = weight / height ** 2 if user_bmi < 18.5: print("Underweight") elif user_bmi >= 18.5 and user_bmi < 25: print("Normal") elif user_bmi >= 25.0 and user_bmi < 30: print("Overweight") elif user_bmi >= 30.0: print("Obesity")
4th Jan 2022, 6:46 PM
Lothar
Lothar - avatar
+ 7
Preeyansh Tibrewal , that is great, congratulations !!!
6th Jan 2022, 3:51 PM
Lothar
Lothar - avatar
+ 2
Lothar Yes that was an issue too but I can proudly say that I figured it out myself yesterday đŸ˜€
5th Jan 2022, 3:26 AM
Preeyansh Tibrewal
Preeyansh Tibrewal - avatar
+ 1
Input weight first, then height.
4th Jan 2022, 2:52 PM
Brian
Brian - avatar
+ 1
It had some other smaller issues too Had to take some time to solve it But that's what helps me improve!
4th Jan 2022, 4:03 PM
Preeyansh Tibrewal
Preeyansh Tibrewal - avatar
0
It says syntax error in line 6 Brian
4th Jan 2022, 3:12 PM
Preeyansh Tibrewal
Preeyansh Tibrewal - avatar