Invalid sintax - Line 8 | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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")

9th Mar 2021, 6:55 PM
Davide Calanna
Davide Calanna - avatar
8 Answers
+ 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")
9th Mar 2021, 7:10 PM
Nazeekk
Nazeekk - avatar
+ 2
When you use "and" operator, you have to write comparable variable again
9th Mar 2021, 7:08 PM
Nazeekk
Nazeekk - avatar
+ 1
in python you could also write: if 18.5 <= BMI < 25: to test if a value is in a range ;)
9th Mar 2021, 8:15 PM
visph
visph - avatar
+ 1
Nazeekk No ways, I had solved this. In python beginners course. ok
9th Mar 2021, 9:39 PM
❤️😍Prerana😍❤️
❤️😍Prerana😍❤️ - avatar
0
... and BMI < 25
9th Mar 2021, 7:04 PM
Oma Falk
Oma Falk - avatar
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")
9th Mar 2021, 8:17 PM
visph
visph - avatar
0
Sathe Prerana Satish I mean, you just copied my answer😳😳
9th Mar 2021, 9:37 PM
Nazeekk
Nazeekk - avatar
- 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')
9th Mar 2021, 9:35 PM
❤️😍Prerana😍❤️
❤️😍Prerana😍❤️ - avatar