In Boolean algebra, we only have two values: True and False.
True
This is fundamental to the understanding of Boolean logic.
What are the three basic operators in Boolean algebra.
These operators are essential for constructing Boolean expressions.
In Python, the not operator is a _______ operator.
unary
It operates on a single Boolean value.
In Python, and and or are _______ operators.
binary
They operate on two Boolean values.
What is the result of not True?
False
The not operator reverses the Boolean value.
What is the result of True or False?
True
The or operator returns True if at least one operand is True.
What is the result of True and False?
False
The and operator returns True only if both operands are True.
What does not (a < b) evaluate to if “a” is greater than “b”?
True
The expression reverses the result of the comparison.
In the expression **(enabled == True) and (withdrawal <= balance),
what does the and operator require?
Both conditions must be True on both sides
(1 == 1) and (2 <= 3)
If either condition is False, the entire expression evaluates to False.
The not operator simply reverses the Boolean value: a not a. What is the result if a is True?
False
This is because it reverses the result.
Always remeber, “not” revererses the outcome.
This demonstrates the negation of a Boolean value.
The and operator returns True if and only if both a and b are _______.
True
This is a key property of the and operator.
What is the result of a and b if a is False?
False
If a is False, the result is always False regardless of b.
The or operator is False if and only if both a and b are _______.
False
This is a fundamental property of the or operator.
What is the result of a or b if a is True?
True
If a is True, the result is always True regardless of b.
What is short-circuited evaluation?
Evaluation stops as soon as the result is determined
This optimizes performance by avoiding unnecessary calculations.
In the context of short-circuited evaluation, if the left operand of and is False, what happens?
The right operand is not evaluated
This is because the overall result will be False.
In the context of short-circuited evaluation, if the left operand of or is True, what happens?
The right operand is not evaluated
This is because the overall result will be True.
Provide an example of short-circuited evaluation in a trading algorithm.
if exchange_open(symbol) and calc_signal(symbol):
This prevents unnecessary calculations when the exchange is closed.