- 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")
9 Réponses
+ 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.
+ 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")
+ 1
In line 6 you wrote
"elif BMI >= 18.5 and <=25"
Try writing
"elif BMI >= 18.5 and BMI <= 25"
See the difference?
+ 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 .
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.
- 1
I'm trying to solve BMI calculator
- 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")