Logical OR in Python
Logical OR requires at least one condition to be met. Such a condition can be written using the operator or.
Let us have two variables:
tst1 = 10
tst2 = -5
Let's write down the condition - if the variable tst1 is greater than 0 or the variable tst2 is greater than 0, then '+++' will be output to the console:
if tst1 > 0 or tst2 > 0:
print('+++') # this will work
else:
print('---')
Given variables:
tst1 = -1
tst2 = 4
Check that the variable tst1 is equal to or less than 1, and the variable tst2 is greater than or equal to 3.
Without running the code, determine what will be output to the console:
tst1 = -10;
tst2 = -10;
if tst1 >= 0 or tst2 >= 0:
print('+++');
else:
print('---');
}
Without running the code, determine what will be output to the console:
tst1 = 0;
tst2 = 0;
if tst1 >= 0 or tst2 >= 0:
print('+++');
else:
print('---');
Without running the code, determine what will be output to the console:
tst1 = 0;
tst2 = 5;
if tst1 >= 0 or tst2 >= 0:
print('+++');
else:
print('---');
Without running the code, determine what will be output to the console:
tst1 = 5;
tst2 = 5;
if tst1 >= 0 or tst2 >= 0:
print('+++');
else:
print('---');
Without running the code, determine what will be output to the console:
tst1 = -5;
tst2 = 15;
if tst1 >= 0 or tst1 >= 0:
print('+++');
else:
print('---');
Without running the code, determine what will be output to the console:
tst = 1;
if tst == 0 or tst == 1:
print('+++');
else:
print('---');
Without running the code, determine what will be output to the console:
tst = 2;
if tst == 0 or tst == 1:
print('+++');
else:
print('---');
Without running the code, determine what will be output to the console:
tst = 2;
if tst == 0 or tst == 1 or tst == 2:
print('+++');
else:
print('---');