I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.
You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.
I’ve honestly never programmed in python in my life and I was able to modify what you have using the logical “and” operator and it worked. I would give it another try.
This is how they explain to do the if statement.
“Indentation is used to define the level of nesting.”
I don’t have any “new” code. I have tried, before coming to this forum, and, or, elif, parenthesis around comparison operators, separate line with and, or, and just entering the variable <
We can’t see any of these attempts and can’t comment on them.
Your code code for making two logical comparisons is wrong. You need to use a logical and. Show us code with a logical and and we can help you fix it.
You are excessively indenting. If you place one if statement inside of another, you will only execute the body of the second if statement when both are true. That will never happen with the comparisons you are making. Show us your code with an if-else on the same level and we can help you fix it.
The logical and needs to have a complete comparison on each side. < 25 is not a complete logical comparison.
Also… You are excessively indenting. None of your code with the higher indentation level will every be able to run because the conditions are exclusive.
“So what are the other comparison operators? Well, we’ve got: equal to ==, not equal to !=, greater than >, smaller than <, greater or equal to >=, smaller or equal to <=.”
So I don’t understand what you mean by complete comparison operator.
Do you mean adding the variable?
If I walk up up to you and say ‘less than twenty-five’, will you have any clue what I mean? What is less than 25? You have not told Python what you want to compare to 25.
In order to use a comparison operator you need a complete expression with 1) a value on the left 2) a comparison operator in the middle and 3) a value on the right.
In order to make two comparisons at once, you need two complete comparison expressions separated by an and.
Yea I tried that b4 and it still didn’t work. I guess I didn’t do it exactly correct. Could have been the nesting. But by example that is the way they show you how to do it. Believe me, I tried just nesting the print function and still couldn’t get it to work. I guess it just wasn’t all done at the same time. Thanks guys. I finally got it.
Weight = float(input())
Height = float(input())
BMI = Weight / (Height**2)
if BMI < 18.5:
print("Underweight")
if BMI >= 18.5 and BMI < 25:
print("Normal")
if BMI >= 25 and BMI < 30:
print("Overweight")
if BMI >= 30:
print("Obesity")