Boolean_Operators Flashcards

(18 cards)

1
Q

In Boolean algebra, we only have two values: True and False.

A

True

This is fundamental to the understanding of Boolean logic.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are the three basic operators in Boolean algebra.

A
  • and
  • or
  • not

These operators are essential for constructing Boolean expressions.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

In Python, the not operator is a _______ operator.

A

unary

It operates on a single Boolean value.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

In Python, and and or are _______ operators.

A

binary

They operate on two Boolean values.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the result of not True?

A

False

The not operator reverses the Boolean value.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the result of True or False?

A

True

The or operator returns True if at least one operand is True.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the result of True and False?

A

False

The and operator returns True only if both operands are True.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What does not (a < b) evaluate to if “a” is greater than “b”?

A

True

The expression reverses the result of the comparison.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

In the expression **(enabled == True) and (withdrawal <= balance),
what does the and operator require?

A

Both conditions must be True on both sides
(1 == 1) and (2 <= 3)

If either condition is False, the entire expression evaluates to False.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

The not operator simply reverses the Boolean value: a not a. What is the result if a is True?

A

False
This is because it reverses the result.
Always remeber, “not” revererses the outcome.

This demonstrates the negation of a Boolean value.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

The and operator returns True if and only if both a and b are _______.

A

True

This is a key property of the and operator.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is the result of a and b if a is False?

A

False

If a is False, the result is always False regardless of b.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

The or operator is False if and only if both a and b are _______.

A

False

This is a fundamental property of the or operator.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is the result of a or b if a is True?

A

True

If a is True, the result is always True regardless of b.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is short-circuited evaluation?

A

Evaluation stops as soon as the result is determined

This optimizes performance by avoiding unnecessary calculations.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

In the context of short-circuited evaluation, if the left operand of and is False, what happens?

A

The right operand is not evaluated

This is because the overall result will be False.

17
Q

In the context of short-circuited evaluation, if the left operand of or is True, what happens?

A

The right operand is not evaluated

This is because the overall result will be True.

18
Q

Provide an example of short-circuited evaluation in a trading algorithm.

A

if exchange_open(symbol) and calc_signal(symbol):

This prevents unnecessary calculations when the exchange is closed.