Can we compare one value with multiple values using 'or'?

OR/AND do no such things. Understanding them might be tricky at first, but you do need to grasp them. In this case, using IN would arguably be better. But can’t always use in, for example:

if x == 11 or y == 12 or z == 12

we couldn’t use IN here.

this is also the reason we can’t do:

if (value == 10 or 11 or 12):

who says we want to compare 11 to value? If that is the intention, use in indeed

or we can simply say that or, not, and are logical operators that needs Boolean output around them. So we can’t compare one with multiple.

this is perfectly possible:

x = 3
y = True

if x == 3 and y:
  print('its true')

we have one comparison (x == 3) and check if y is truthy.

if we need to compare with multiple values, we can simple use in keyword

1 Like

Now this explaination is a lot better than the first. I was confused when you stated that both “if” statments, reguardless of the variable “value” had assigned to it, will just end in “True” just because of the expression “value == 10”.

You made it more clearer when you broke down the Python logic when it goes to the print statement.

The first “if” statement does exactly what you said it would do…but the second goes to the “next” operation of “or” and associates that to “True” and terminates.

why did you have to wrap it in quote

it in quotes? The use of reference words (it) without any previous context doesn’t work

in the exercise of CONTROL FLOW
Boolean Operators: or in python, even if my answer is matching with the solution still am not able to get right, why ao?

if credits >= 120 or gpa >= 2.0:

print(“You have met at least one of the requirements.”)

please post your full code

because the instruction tells us we need to meet at least one requirement, in this case or is necessary:
“Write an if statement that checks if a student either has 120 or more credits or a GPA 2.0 or higher”

I wrote the next equation in my IDLE and it works:

statement_two = 2+2
if statement_two >= 15 or 10 or 4:
print(“Hello!”)

So, why do we need to do the following: “each comparison must be separate and
valid on their own on each side of each “or”.”?

statement_two = 0
if statement_two >= 15 or 10 or 4:
    print("Hello!")

Should this print "Hello"?
0 isn’t greater than or equal to any of 15 or 10 or 4 and yet your code still prints "Hello"

Your statement is being interpreted as:

Spoiler
if (statement_two >= 15) or (10) or (4):

# The first operand is False, but the second operand 10 is
# truthy. So, this if statement will always evaluate to True
# regardless of what value you assign to statement_two.
2 Likes

Whhaaaa. Thank you!)) It’s much deeper than I thought.

1 Like

Hey all!

Can we get some more justification on this statement made in “Control Flow: Boolean Operators: or”:

In English, or implies that if one component is True , then the other component must be False .

From my understanding, and after a bit of study in laws, an or means that each/every statement connected with an or stands on its own and it evaluated on its own. Whoever wrote this and put a must in here, if you could please provide justification so that we can understand more fully.

Thanks!