- 2
Can you tell me what's wrong in this code
Python basics https://code.sololearn.com/cWoQJdO3jTLo/?ref=app https://code.sololearn.com/cWoQJdO3jTLo/?ref=app
9 Respostas
+ 7
Wesam Sobhy ,
(referring to your *updated code*)
sorry to say, but the conditional expressions and the structure how they are ordered looks weird, so we can not pass the test cases.
e.g.: weight = 130, height = 1.7
result is:
Obesity
Normal
Overweight
> instead of using individual *if...* we should use something like: *if... elif... else...*
> also there is still a typo in an *if*
> this is how it could be done:
if BMI < 18.5:
...
elif BMI >= 18.5 and BMI < 25:
...
elif BMI >= 25.0 and BMI < 30:
...
elif BMI >= 30.0:
...
> i would recommend you to learn again about conditional statements before you continue with other stuff.
+ 3
There are several issues:
* The division operator in Python is "/", not "\"
* The output must be strings. Strings have quotation marks around it. Compare "Underweight" vs. Underweight. Also check for typos.
* Look up how conditions are chained in Python.
* Suppose the BMI was 18. Your current code would output Underweight as well as Obesity which shouldn't be true.
+ 2
Please show your updated code.
+ 2
Wesam Sobhy check output for BMI 30 by going through your code.
Last 3 conditions met true.
+ 1
weight= 0
hight= 0
weight = int (input())
hight= float (input ())
BMI= weight / hight**2
if BMI < 18.5 :
print ("Underweight")
If BMI>= 30:
print ("Obesity")
if BMI>= 18.5<25:
print ("Normal ")
if BMI>=25<30:
print ("Overweight ")
+ 1
Ok
+ 1
Thank you
0
I have two wrong answers, which are, BMI = 44.9 and BMI = 26
How can I solve them please
The other three outputs are right
Thanks in advance
0
The division operator is wrong.
The print statements have no quotations.
The naming for height is quite weird.
I think you should use and operator.