0
I want to design Bml calculator, But I do not know where the mistake in the code
# weight = 85 kg # height = 1.9 meters x = 23.5 # x = weight / height^2 if x < 18.5 print ( " Under weight " ) if 25 < x >= 18.5 print ( " Normal " ) if 30 < x >= 25 print ( " Overweight " ) if x >=30 print ( " Obesity " )
4 Answers
+ 3
there are lot of mistakes in your code:
you must take input from user, not hardcode values
the if statement blocks must be indented if not one statement inlined and confition(s) must be followed by a colon (:)
short form of range test should be either min <= val < max OR max > val >= min (max < val >= min is no sense as max cannot be less than min)
"Underweight" shoukd be written in one word (without space) and all output strings may not contains start and end spaces
anyway, ^ in python is the bitwise XOR operator, not the exponant operator (**)... if you use it outside comment, you will get wrong value...
weight = float(input())
height = float(input())
x = weight / height**2
if x < 18.5:
print("Underweight")
if 25 > x >= 18.5:
print("Normal")
if 30 > x >= 25:
print("Overweight")
if x >=30:
print ("Obesity" )
+ 3
Take user input for weight and height.
Uncomment x formula
Delete x = 23.5
Not "Under weight", print "Underweight"
After each if condition write colons
+ 2
Take user input
0
Use ** operator rather than ^ when you want to raise a number to power of another.
Please indent your code, indentation is crucial in Python code.