+ 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")

4th Mar 2021, 1:24 AM
Ava
Ava - avatar
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
4th Mar 2021, 1:38 AM
ChaoticDawg
ChaoticDawg - avatar
+ 3
Thank you all for helping. I found an answer by doing a Google search but thank y'all!šŸ™‚
4th Mar 2021, 3:35 AM
Ava
Ava - avatar
+ 1
Thank you but it says the operation weight/height**2 is not supported or something like that
4th Mar 2021, 3:08 AM
Ava
Ava - avatar
+ 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())
4th Mar 2021, 3:12 AM
ChaoticDawg
ChaoticDawg - avatar
+ 1
Could someone please give me the proper code so that I can look at it and get a better understanding of it?
4th Mar 2021, 3:22 AM
Ava
Ava - avatar
+ 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")
4th Mar 2021, 3:26 AM
ChaoticDawg
ChaoticDawg - avatar