- 3

Can someone please tell me what is wrong here?

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

19th Jun 2022, 6:58 AM
matthew ochefio
matthew ochefio - avatar
7 Antworten
+ 1
matthew ochefio see Manav Roy's code that shows how to take input, which is necessary for Code Coach trials. Also, there is no need to check BMI>=18.5 if you already compared BMI<18.5 and found it false. Likewise for the 25 threshold. You need to correct the comparison from BMI<=25 to BMI<25.
19th Jun 2022, 9:03 AM
Brian
Brian - avatar
+ 1
Here's the answer: weight = 85 height = 1.9 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") else: print("Obesity")
20th Jun 2022, 5:48 AM
EmmzyCodez
EmmzyCodez - avatar
+ 1
In line 6 you wrote "elif BMI >= 18.5 and <=25" Try writing "elif BMI >= 18.5 and BMI <= 25" See the difference?
20th Jun 2022, 11:45 AM
Umar Muhammad
Umar Muhammad - avatar
+ 1
matthew ochefio in elif statement you are using 'and' but in the right side expression you haven't gave the VARIABLE . Check it out once .
20th Jun 2022, 6:45 PM
Sirigiri Manohar Reddy
0
Common errors in your code (Improvement) Use variable name for comparison always.... for eg.. BMI>=18.5 and BMI<25:........✅️ BMI>=18.5 and <25:...........❎️ Here is complete code in correct way (that you want) ..... weight=85 height=16.5 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") else: print("Obesity") There are another way, in which you can take input from users that is explained by another user in your ANSWER. HOPE IT WILL HELP YOU TO GET ERRORS IN YOUR CODE.
21st Jun 2022, 1:36 AM
Anurag Chaurasiya
Anurag Chaurasiya - avatar
- 1
I'm trying to solve BMI calculator
19th Jun 2022, 7:12 AM
matthew ochefio
matthew ochefio - avatar
- 1
matthew ochefio here is the write code weight = 85 height = 1.9 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") else: print("Obesity")
20th Jun 2022, 6:42 PM
Sirigiri Manohar Reddy