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??
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.
+ 1
0
You are using the assignment operator (=), you want to use (==) which does comparisons for equality.
0
I tried use (==) but the same error appears 😕
0
Can you share you updated code as a code bit (not just text so it's easier to debug)?
0
I solved it
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")