Why this doesn't work and what is the answer | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Why this doesn't work and what is the answer

#This is a project BMI calcutor help me python weight = int(input()) height = float(input()) BMI = weight / height* 2 if BMI < 18.5: print("Underweight") elif BMI >= 18.5: print("normal") elif BMI >= 25: print("Overweight") elif BMI >= 30: print("Obesity")

26th Jan 2023, 9:39 AM
Afnan Chowdhury
Afnan Chowdhury - avatar
4 Answers
+ 1
Afnan Chowdhury the BMI calculation is wrongly doubling height instead of squaring height. The logic tests BMI<18.5, and then tests BMI>=18.5, which always would be true if the first test fails, making all other tests after that unreachable. Make the logic consistent. if BMI<18.5: ... elif BMI<25: ... elif BMI<30: ... else: ...
26th Jan 2023, 8:52 PM
Brian
Brian - avatar
26th Jan 2023, 9:55 AM
Darpan kesharwani🇮🇳[Inactive📚]
Darpan kesharwani🇮🇳[Inactive📚] - avatar
0
The formula for BMI is weight in kilograms divided by height in meters squared. If height has been measured in centimeters, divide by 100 to convert this to meters. In order to square the height you have to write height**2. Hope that helps.
26th Jan 2023, 9:56 AM
Thomas Lipovec
Thomas Lipovec - avatar
0
Thanks tuk tuk
26th Jan 2023, 12:20 PM
Afnan Chowdhury
Afnan Chowdhury - avatar