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

14th Jun 2021, 10:54 AM
Hager mohamed Yahia
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" )
14th Jun 2021, 3:25 PM
visph
visph - avatar
+ 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
14th Jun 2021, 11:13 AM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
+ 2
Take user input
14th Jun 2021, 10:58 AM
Atul [Inactive]
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.
14th Jun 2021, 12:22 PM
Ipang