0

BMI calculator

I am a beginner at Python At this test I want to use While loop like this: h = float(input()) w = float(input()) while BMI = w / h**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') break But the error message appears: while BMI = w / h**2: ^ SyntaxError: invalid syntax where is the wrong??

20th May 2022, 1:13 PM
Amira Ramadan Ali Abdelaal
7 Answers
+ 1
Why you need loop there? Remove it. And just use BMI = w/ h**2 looks like first input, second inputs are swapped.! do check again.
20th May 2022, 1:24 PM
Jayakrishna 🇮🇳
20th May 2022, 1:30 PM
Amira Ramadan Ali Abdelaal
0
You are using the assignment operator (=), you want to use (==) which does comparisons for equality.
20th May 2022, 1:15 PM
Justice
Justice - avatar
0
I tried use (==) but the same error appears 😕
20th May 2022, 1:16 PM
Amira Ramadan Ali Abdelaal
0
Can you share you updated code as a code bit (not just text so it's easier to debug)?
20th May 2022, 1:23 PM
Justice
Justice - avatar
0
I solved it
20th May 2022, 1:36 PM
Amira Ramadan Ali Abdelaal
0
I was forgetting to capitalize the strings and that was my problem weight = float(input()) height = float(input()) bmi = weight / (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") elif bmi >= 30: print("Obesity")
3rd Jun 2022, 5:53 AM
Zack Mclain