0
Problem with BMI calculator Problem in Python
I've tried multiple times to successfully clear the problem and it constantly errors. I ran it through the pydroid 3 app and it ran perfectly. Idk what the issue is... Here is the code h=float(input("Enter the height in cm: ")) w=float(input("Enter the weight in kg: ")) BMI=w/(h*h) if(BMI<18.5): print("Underweight") elif(BMI>=18.5): print("Normal") elif(BMI>=25): print("Overweight") elif(BMI>=30): print("Obesity")
3 Respostas
+ 3
Ghostflake
Also, Sololearn does not process input similar to externali IDE's.
Your prompts within the inputs will create errors in the challenges.
May I suggest:
h = float(input()) # height in cm
w = float( input()) # weight in kg
+ 3
You don't need to use the double condition check that Per Bratthammar has said. Yes, it will definitely work, but you don't have to do it that way.
Another way, you can chop off all the values less than your check. The if ensures that the first elif doesn't get to see values less than 18.5 the next elif chops off more, the else is anything not smaller than the last elif.
(NOTE: Gotta check from smallest to biggest, gotta use "less than" as your check.)
You could instead check from smallest to largest, eg:
if (BMI<18.5): #chops values at 18.5
###
elif (BMI<25): # doesn't see anything below 18.5, cuts at 25
###....
###....
else print("Obesity") # takes any remaining values.
+ 2
Hi! In that way you write your conditions, if BMI = 27, it still will print Normal, because BMI >= 18.5.
One way is to write your condition in this way:
elif 18.5 <= BMI < 25:
print(”Normal”)
etc…