- 2
What's wrong with this code
#BMI CALCULATOR weight = int(input("in Kg:")) height = float(input("in meters:")) BMI=(weight /(height **2)) print(BMI) if (BMI < 18.5): print ("Underweight") else: if BMI >= 18.5 and < 25: else: print ("Normal") else: if (BMI >= 25 and < 30): print ("Overweight") else: if (BMI>= 30): print ("Obesity")
4 Respuestas
+ 2
Click on your "bmi" tag and you'll see hundreds of replies.☺️
+ 2
I think there are a few issues with your "if/else/if" lines.
You probably want to re-read that section of the tutorial.
I think it should look like:
if (condition)
//code
elif (condition)
//code
else
//code
0
instead of:
and <
you should write:
and BMI <
Also delete every line that has "else:".
And fix the indentation - each (of the remaining) lines that ends in ":" should be followed by an indented line.
Like this:
if (BMI < 18.5):
print ("Underweight")
if BMI >= 18.5 and BMI < 25:
print ("Normal")
if (BMI >= 25 and BMI < 30):
print ("Overweight")
if (BMI>= 30):
print ("Obesity")
It's not the best, but it should work as intended.
- 1
weight = float(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')