1

Here is the code:

Weight = float(input("Enter weight in Kilograms: "))
Height = float(input("Enter height in meters: "))
BMI = (Weight / (Height**2))
print ("%.2f" %BMI)
if BMI < 18.5:
    print ("You are under weight")
elif BMI >= 18.5 and < 25.0:
    print ("You weight is normal")
elif BMI >= 25.0 and < 30.0:
    print ("You are overweight")
elif BMI >= 30.0:
    print ("You are overweight")

Getting invalid syntax at the line elif BMI >= 18.5 and < 25.0:

Srini
  • 227
  • 2
  • 3
  • 10
  • 1
    http://stackoverflow.com/questions/15112125/how-do-i-test-one-variable-against-multiple-values is not a duplicate, but definitely explains how to do it right. – Adam Smith Feb 18 '15 at 02:26

1 Answers1

5

>, <, and the rest are binary operators. It's looking for an operand on each side, and when it finds a keyword on its left and < 25.0 throws a SyntaxError.

The normal way to do this is:

if BMI >= 18.5 and BMI < 25.0:

But there is a shortcut for inequalities:

if BMT < 18.5:
    # underweight
elif 18.5 <= BMI < 25.0:
    # normal
elif 25.0 <= BMI < 30:
    # overweight
elif 30 <= BMI:
    # super overweight
Adam Smith
  • 52,157
  • 12
  • 73
  • 112