+ 3
What is wrong with my code?
Please help me with BMI calculator project in Python for Beginner's. This is my code: height=input(float()) weight=input(float()) bmi=(weight/height**2) if bmi<18.5: print("Underweight") elif bmi>=18.5: elif bmi<25: print("Normal") elif bmi>=25: elif bmi<30: print("Overweight") else: print("Obesity")
7 Answers
+ 4
1. Your indentation is nesting invalid elif statements within an elif statement. These elif statements are floating statements and don't seem to belong to any if-elif blocks.
2. You need to check if the bmi value is between 18.5 AND 25
I.E. 18.5 <= bmi < 25
Same for 25 - 30
25 <= bmi < 30
+ 3
Thank you all for helping. I found an answer by doing a Google search but thank y'all!š
+ 1
Thank you but it says the operation weight/height**2 is not supported or something like that
+ 1
Ava fix your if-elif-else, so that it is valid code. Everything above that looks good from what you have posted here so far.
Edit: you're getting your inputs in the wrong order (weight then height) and you need to convert the input to float like;
float(input()) not input(float())
+ 1
Could someone please give me the proper code so that I can look at it and get a better understanding of it?
+ 1
Ava Sorry, after a second look at your OP I noticed that you were also getting your inputs wrong.
w = float(input())
h = float(input())
bmi = w / h**2
if bmi < 18.5:
print("Underweight")
elif 18.5 <= bmi < 25:
print("Normal")
elif 25 <= bmi < 30:
print("Overweight")
else:
print("Obesity")