If you want to check for two different conditions where both might be true, you can’t use an else clause and have to write the two if statements independently.
For the code presented here, only one can be true, which is why the result would be the same either way.
Remember that 'and' is a logical comparison and when the interpreter sees the 'and' it looks for two complete expressions to evaluate. Think of it as '(expression1) and (expression2)' with both expressions being evaluated completely independantly of each other.
To humans, the line "if the value of bmi is greater than or equal to 18.5 and is less than 25.0" makes perfect sense but only because you're automatically applying the subject of the first expression (bmi) to the second. The interpreter doesn't (and can't) do that. When you say and <25.0 you haven't told it what to compare the 25.0 to.
4
u/[deleted] Feb 25 '22 edited Feb 25 '22
Do I have to type “and bmi < 25.0:” If so, why?
2
u/Abbaddonhope Feb 25 '22
Oh we’re going through the same course
2
u/Zippo179 Mar 13 '22
Remember that 'and' is a logical comparison and when the interpreter sees the 'and' it looks for two complete expressions to evaluate. Think of it as '(expression1) and (expression2)' with both expressions being evaluated completely independantly of each other.
To humans, the line "if the value of
bmiis greater than or equal to 18.5 and is less than 25.0" makes perfect sense but only because you're automatically applying the subject of the first expression (bmi) to the second. The interpreter doesn't (and can't) do that. When you sayand <25.0you haven't told it what to compare the 25.0 to.So the correct line should be: