+ 1
Invalid sintax - Line 8
weight = 85 height = 1.9 BMI = (float(weight / height**2)) if BMI < 18.5: print("Underweight") else: if BMI >= 18.5 and < 25: print("Normal") else: if BMI >= 25 and < 30: print("Overweight") else: if BMI >=30: print("Obesity")
8 Respuestas
+ 3
So here we go:
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")
elif BMI >=30:
print("Obesity")
+ 2
When you use "and" operator, you have to write comparable variable again
+ 1
in python you could also write:
if 18.5 <= BMI < 25:
to test if a value is in a range ;)
0
... and BMI < 25
0
also, as you first test for lowest bound, next you don't have to test for it:
So here we go:
weight = int(input())
height = float(input())
BMI = (weight / height**2)
if BMI < 18.5:
print("Underweight")
elif BMI < 25: # necessarly BMI >= 18.5
print("Normal")
elif BMI < 30: # necessarly BMI >= 25
print("Overweight")
else: # necessarly BMI >= 30
print("Obesity")
0
Sathe Prerana Satish
I mean, you just copied my answer😳😳
- 1
Davide Calanna
Try this:
#your code goes here
weight = int(input());
height = float(input());
bmi = weight/float(height*height);
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')