0
Why the output is showing all my if cases?
8 odpowiedzi
+ 5
Example using your second if
if 15>=bmi<16:
if bmi is 14, then both 15>=14 and 14<16 are True so the if is True. You need to change it to
if 15<=bmi<16:
+ 5
because all your if conditions are getting true.
change your,
if 15>=bmi<16:
to
if bmi>=15 and bmi<16:
and all the others too.
+ 5
Abhijith Mulavana instead of using a bunch of if statements only, use
if
elif
else
+ 5
if bmi < 15:
...
elif bmi < 16:
...
You won't need to check if bmi >= 15 because that will be implied by the first if return False.
+ 3
Your conditions are always true because, for example, 15 >= bmi < 16 is basically the same as bmi <= 15 and bmi < 16, which is true for all numbers less than or equal to 15. If the computed bmi is, let's say 10, it will trigger all the other similar if statements because bmi is less than all of the numbers used in their conditions.
Similar to what Russ said, if you want a condition in Python that checks if a number (bmi) is between two other numbers (15 and 16), you can write your condition like this:
15 < bmi < 16,
which is the same as saying:
15 < bmi and bmi < 16
or
bmi > 15 and bmi < 16
You can also make use of elif and else statements:
if bmi < 15:
...
elif bmi < 16:
...
...
elif bmi < 40:
...
else:
...
- 1
In html, When i use / for ending code it displays the same results as without / why?plz answer me also