0
Whats the error i dont understand
height=float(input()) weight=float(input()) x=weight/(height**2) if x<18.5 : print ("Underweight") elif (x>=18.5 & x<=25): print ("Normal") elif (x>=25 & x<=30): print ("Overweight") else: print ("Obesity")
5 Respuestas
+ 3
In Python "&" is used for bitwise operations.
https://www.w3schools.com/python/python_operators.asp
+ 2
In Python you don't use &, you should use the expression "and"
x >=18.5 and x<=25
+ 1
your code snipped is wrong, as others already explained. Also I suggest one of following two code changes to clarify the algorithm.
With ifs you need check low and high limits of x.
if x<18.5:
print ("Underweight")
if (x>=18.5 and x<25):
print ("Normal")
If x>30:
#obesity
With elifs you just need to check high limits of x.
if x<18.5:
print ("Underweight")
elif x<25:
print ("Normal")
else:
#obesity
Either use only ifs or remove the lower limit checks at your elifs.
+ 1
Replace the ampersand symbol with 'and'.
(Use : 'and', not '&' in your code)
Code: ...
elif (x>= 18.5 and x<=25):
0
Observe the correct order of inputs given. Yours are reversed.