0
BMI Calculator (Python3)
Hey, I've been trying to figure out the BMI Calculator problem. Can someone please help me? Here is what I've written so far: weight = int(input()) if weight < 18.5: print("Underweight") else: if weight >= 18.5 and < 25: print("Normal") else: if weight >= 25 and < 30: print("Overweight") else: if weight > 30: print("Obesity") -- I get the error: --- File "/usercode/file0.py", line 5 if weight >= 18.5 and < 25: ^ SyntaxError: invalid syntax
6 RĂ©ponses
+ 2
hi! you don't compare anything to <25
+ 5
On either side of the AND, you need to write a full evaluation. weight > 18.5 and weight < 30. You need this in all your tests. However, the better method is to use if / elif:
if weight < 18.5:
print(âUnderweightâ)
elif weight < 25:
print(âNormalâ)
elif weight < 30:
print(âOverweightâ)
else:
print(âObesityâ)
This method simplifies the tests and because of using elif, you donât have to test for conditions already found above.
0
It should like
if weight>= 18.5 and weight < 25 :
Or simply (in python)
if 25 > weight >=18.5:
0
Ohh, thank you! I'm one step closer to completing it now. I'll do the rest by myself.
0
w = float(input())
h = float(input())
x = ("w/h**2")
if x < 18.5:
print("Underweight")
elif x < 25:
print("Normal")
elif x < 30:
print("Overweight")
else:
print("Obesity")
And
Traceback (most recent call last):
File "/usercode/file0.py", line 4, in <module>
if x < 18.5:
TypeError: '<' not supported between instances of 'str' and 'float'
0
Weight=int(input())
Height=float(input())
Bmi= Weight/(Height*Height)
if Bmi < 18.5:
print("Underweight")
elif Bmi < 25:
print("Normal")
elif Bmi < 30:
print ("Overweight")
else:
print ("Obesity")
It took a while but I was able to get the results with this method. Try and see if it works.