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

19th Mar 2021, 8:36 PM
Aron
Aron - avatar
6 Respostas
+ 2
hi! you don't compare anything to <25
19th Mar 2021, 8:40 PM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
+ 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.
19th Mar 2021, 8:48 PM
Jerry Hobby
Jerry Hobby - avatar
0
It should like if weight>= 18.5 and weight < 25 : Or simply (in python) if 25 > weight >=18.5:
19th Mar 2021, 8:42 PM
Jayakrishna 🇮🇳
0
Ohh, thank you! I'm one step closer to completing it now. I'll do the rest by myself.
19th Mar 2021, 8:50 PM
Aron
Aron - avatar
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'
13th Oct 2021, 5:00 AM
Jeazer_N
Jeazer_N - avatar
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.
1st Mar 2022, 3:31 PM
Zena Aganmwonyi