Calculating BMI | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Calculating BMI

#whats wrong please help weight = float(input()) height = float((input()) BMI = weight / height * height print(BMI) if BMI < 18.5: print("Underweight") elif (18.5 <= BMI < 25): print("Normal") elif (25 <= BMI < 30): print("Overweight") else: if BMI >= 30: print("Obesity") # #

13th Aug 2021, 11:37 AM
Sukoluhle Dube
4 Answers
+ 5
#whats wrong please help weight = float(input()) #There is an extra parenthesis height = float(input()) #You need to use `**` operator instead of `*` since ** operator has higher precedence than * BMI = weight / height ** 2 #print(BMI) if BMI < 18.5: print("Underweight") elif (18.5 <= BMI < 25): print("Normal") elif (25 <= BMI < 30): print("Overweight") else: if BMI >= 30: print("Obesity")
13th Aug 2021, 11:45 AM
Simba
Simba - avatar
+ 3
Your comparison statements need to be adjusted. Example: elif BMI >= 18.5 < 25: # if BMI is greater than or equal to 18.5 but smaller than 25
13th Aug 2021, 11:45 AM
Rik Wittkopp
Rik Wittkopp - avatar
13th Aug 2021, 11:44 AM
VSR [ DEV ]
VSR [ DEV ] - avatar
+ 1
weight = int(input()) height = float(input()) BMI = weight / (height**2) if BMI < 18.5: print("Underweight") elif BMI >= 18.5 and BMI < 25: print("Normal") elif BMI >= 25 and BMI < 30: print("Overweight") else: print("Obesity")
13th Aug 2021, 11:43 AM
Apongpoh Gilbert
Apongpoh Gilbert - avatar