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")

18th Dec 2021, 2:47 PM
Mh Shawon
Mh Shawon - avatar
5 Respuestas
+ 3
In Python "&" is used for bitwise operations. https://www.w3schools.com/python/python_operators.asp
18th Dec 2021, 3:24 PM
Simon Sauter
Simon Sauter - avatar
+ 2
In Python you don't use &, you should use the expression "and" x >=18.5 and x<=25
18th Dec 2021, 2:57 PM
Anya
Anya - avatar
+ 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.
20th Dec 2021, 12:42 AM
Rick Richard
+ 1
Replace the ampersand symbol with 'and'. (Use : 'and', not '&' in your code) Code: ... elif (x>= 18.5 and x<=25):
20th Dec 2021, 11:44 AM
Nana Senne Ackaah Gyasi
Nana Senne Ackaah Gyasi - avatar
0
Observe the correct order of inputs given. Yours are reversed.
18th Dec 2021, 11:53 PM
Brian
Brian - avatar