w3resource

PCEP-30-02 Exam Prep: Mastering Boolean Operators in Python

PCEP Certification Practice Test - Questions, Answers and Explanations

This comprehensive set of questions and explanations covers the fundamental topic of choosing operators and data types adequate to the problem, focusing on Boolean operators: not, and, or. This diverse set of interactions enhances understanding and prepares for the PCEP-30-02 examination.

Question 1: What is the result of the following Boolean expression?

True and False
  1. True
  2. False
  3. None
  4. 0

Answer: b) False

Explanation: The and operator requires both operands to be True for the result to be True. Since one operand is False, the result is False.

Question 2: What does the following Boolean expression evaluate to?

not (True or False)
  1. True
  2. False
  3. None
  4. 0

Answer: b) False

Explanation: True or False evaluates to True. The not operator inverts True to False.

Question 3: Which of the following Boolean expressions is True?

  1. False and True
  2. not (True or True)
  3. True or False
  4. not (False or False)

Answer: c) True or False, d) not (False or False)

Explanation: True or False: This expression is evaluates to True because at least one operand is True, and not (False or False): This expression is True because False or False is False, and not False is True.

Question 4: Which of the following Boolean expressions are True? (Select all that apply)

  1. not False
  2. True and not False
  3. False or not True
  4. not (True and False)

Answer: a) not False, b) True and not False, d) not (True and False)

Explanation: not False is True, True and not False is True, and not (True and False) is True.

Question 5: Which of the following Boolean expressions are False? (Select all that apply)

  1. not True
  2. True and False
  3. False or False
  4. not (False or True)

Answer:a) not True, b) True and False, c) False or False, d) not (False or True)

Explanation: not True is False, True and False is False, False or False is False, and not (False or True) is False.

Question 6: Place the following Boolean expressions in the correct order of their typical usage: not, and, or.

  • not
  • and
  • or

Answer:

  • not
  • and
  • or

Explanation: According to operator precedence, not is evaluated first, followed by and, and then or.

Question 7: Arrange the following Boolean expressions to evaluate the expression x = not (True or False) and True correctly: not (True or False), x = y and True, y = not (True or False).

Answer:

  • y = not (True or False) (evaluates to False)
  • not (True or False) (evaluates to False)
  • x = y and True (evaluates to False)

Explanation: First, evaluate not (True or False) to get False. Then, use y = False and evaluate x = y and True to get False.

Question 8: The operator that has the highest precedence among Boolean operators is ______.

Answer: not

Explanation: The not operator has a higher precedence than and and or.

Question 9: The expression False or not True and True is evaluated by performing the ______ operation first.

result = ~x

Answer: not

Explanation: According to operator precedence, not is performed before and and or.

Question 10: Sort the following operations to correctly evaluate True or not False and False: not False, True or True, True and False.

Answer:

  1. not False (result: True)
  2. True and False (result: False)
  3. True or False (result: True)

Explanation: The results of the operations are evaluated in the order of their precedence: not, and, and or.

Question 11: Sort the following expressions in ascending order of their results: True or False, True and not False, not True and False, not (False or True).

Answer:

  • not True and False (result: False)
  • not (False or True) (result: False)
  • True and not False (result: True)
  • True or False (result: True)

Explanation: The results of the operations are False, False, True, and True respectively when evaluated correctly.

Question 12: Fill in the missing code to correctly compute the result of True or not (False and True).

result = True or not (False ______ True)

Answer: and

Explanation: The and operator is used for logical conjunction. The correct code is result = True or not (False and True).

Question 13: Fill in the missing code to correctly compute the result of not (True and False) or True.

result = not (True ______ False) or True

Answer: and

Explanation: The and operator is used for logical conjunction. The correct code is result = not (True and False) or True.

Question 14: Insert the correct operator to evaluate not (a and b) where a = True and b = False.

a = True
b = False
result = not (a ______ b)

Answer: and

Explanation: The and operator is used for logical conjunction. The correct code is result = not (a and b).

Question 15: Insert the correct operator to evaluate a or not b where a = False and b = True.

a = False
b = True
result = a ______ not b

Answer: or

Explanation: The or operator is used for logical disjunction. The correct code is result = a or not b.

Question 16: What is the result of the following expression?

not (True or False) and False
  1. True
  2. False
  3. None
  4. 0

Answer: b) False

Explanation: True or False evaluates to True. not True evaluates to False. False and False evaluates to False.

Question 17: Which of the following expressions is False?

  1. not (False or True)
  2. True and not False
  3. False or True
  4. not (True and False)

Answer: a) not (False or True)

Explanation: False or True evaluates to True, and not True evaluates to False.

Question 18: Which of the following statements about Boolean operator precedence are true? (Select all that apply)

  1. not has higher precedence than and.
  2. and has higher precedence than or.
  3. or has higher precedence than not.
  4. not has the lowest precedence among Boolean operators.

Answer: a) not has higher precedence than and., b) and has higher precedence than or.

Explanation: not has higher precedence than and and or. and has higher precedence than or.

Question 19: What are the results of the following code? (Select all that apply)

a = True and not False
b = False or not True
c = not (True and False)
  1. a is True
  2. b is False
  3. c is True
  4. a is False

Answer: a) a is True, b) b is False, c) c is True

Explanation: a = True and not False evaluates to True. b = False or not True evaluates to False. c = not (True and False) evaluates to True.

Question 20: The ______ operator is evaluated before the and operator.

Answer: not

Explanation: The not operator has higher precedence than the and operator.

Question 21: The expression True or False and not True is evaluated by performing the ______ operation first.

Answer:not

Explanation:According to operator precedence, not is performed before and and or.

Question 22: Sort the following operations to correctly evaluate not True or False and True: not True, False and True, False or True.

Answer:

  1. not True (result: False)
  2. False and True (result: False)
  3. False or False (result: False)

Explanation: The results of the operations are evaluated in the order of their precedence: not, and, and or.

Question 23: Sort the following expressions in descending order of their results: True and False, not (False or True), False or True, not (True and False).

Answer:

  • False or True (result: True)
  • not (True and False) (result: True)
  • not (False or True) (result: False)
  • True and False (result: False)

Explanation: The results of the operations are True, True, False, and False respectively when evaluated correctly.

Question 24: Fill in the missing code to correctly compute the result of not (True or False).

result = not (True ______ False)

Answer: or

Explanation: The or operator is used for logical disjunction. The correct code is result = not (True or False).

Question 25: Fill in the missing code to correctly compute the result of True and not False or True.

result = True and not False ______ True

Answer: or

Explanation: The or operator is used for logical disjunction. The correct code is result = True and not False or True.

Question 26: Insert the correct operator to evaluate not (a or b) where a = False and b = True.

a = False
b = True
result = not (a ______ b)

Answer: or

Explanation: The or operator is used for logical disjunction. The correct code is result = not (a or b).

Question 27: Insert the correct operator to evaluate a and not b where a = True and b = False.

a = True
b = False
result = a ______ not b

Answer: and

Explanation: The and operator is used for logical conjunction. The correct code is result = a and not b.

Question 28: What is the result of the following expression?

not (True and False)
  1. True
  2. False
  3. None
  4. 0

Answer: a) True

Explanation: True and False evaluates to False. The not operator inverts False to True.

Question 29: What does the following expression evaluate to?

True or False and False
  1. True
  2. False
  3. None
  4. 0

Answer: a) True

Explanation: According to operator precedence, and is evaluated before or. So, False and False evaluates to False, and then True or False evaluates to True.

Question 30: Which of the following is True?

  1. not True and False
  2. not (True or False)
  3. not (False or False)
  4. not (True and True)

Answer: c) not (False or False)

Explanation: False or False evaluates to False, and not False evaluates to True.

Question 31: Which of the following expressions are True? (Select all that apply).

  1. not (False and True)
  2. True or not False
  3. False and not False
  4. not (True or True)

Answer: a) not (False and True), b) True or not False

Explanation: not (False and True) is True because False and True is False, and not False is True. True or not False is True because not False is True, and True or True is True.

Question 32: Which of the following are False? (Select all that apply)

  1. True and not False
  2. not (True and False)
  3. False or not True
  4. not (False or True)

Answer: c) False or not True, d) not (False or True)

Explanation: False or not True is False because not True is False, and False or False is False. not (False or True) is False because False or True is True, and not True is False.

Question 33: Place the following operations in the correct order of evaluation: True and not False, not (True and False), True or False and False.

Answer:

  1. not (True and False) (evaluates to True)
  2. True or False and False (evaluates to True)
  3. True and not False (evaluates to True)

Explanation: not (True and False) evaluates True and False first (which is False), then applies not to get True. True or False and False evaluates False and False first (which is False), then applies True or False to get True. True and not False applies not to False first to get True, then evaluates True and True to get True.

Question 34: Arrange the following code snippets to evaluate the expression x = True and not (False or True) correctly: not (False or True), x = True and y, y = False or True.

Answer:

  1. y = False or True (evaluates to True)
  2. not (False or True) (evaluates to False)
  3. x = True and y (evaluates to False)

Explanation: First, evaluate y = False or True to get True. Then, apply not to True to get False. Finally, evaluate x = True and False to get False.

Question 35: The operator that has the highest precedence among Boolean operators is ______.

Answer: not

Explanation: The not operator has a higher precedence than and and or.

Question 36: The expression False or not True and True is evaluated by performing the ______ operation first.

Answer: not

Explanation: According to operator precedence, not is performed before and and or.

Question 37: Sort the following operations to correctly evaluate True or not False and False: not False, True or True, True and False.

Answer:

  1. not False (result: True)
  2. True and False (result: False)
  3. True or False (result: True)

Explanation: The results of the operations are evaluated in the order of their precedence: not, and, and or.

Question 38: Sort the following expressions in ascending order of their results: True or False, True and not False, not True and False, not (False or True).

Answer:

  1. not True and False (result: False)
  2. not (False or True) (result: False)
  3. True and not False (result: True)
  4. True or False (result: True)

Explanation: The results of the operations are False, False, True, and True respectively when evaluated correctly.

Question 39: Fill in the missing code to correctly compute the result of True or not (False and True).


result = True or not (False ______ True)

Answer: and

Explanation: The and operator is used for logical conjunction. The correct code is result = True or not (False and True).

Question 40: Insert the correct operator to evaluate not (a and b) where a = True and b = False.


a = True
b = False
result = not (a ______ b)

Answer: and

Explanation: The and operator is used for logical conjunction. The correct code is result = not (a and b).

Question 41: Insert the correct operator to evaluate a or not b where a = False and b = True.


a = False
b = True
result = a ______ not b

Answer: or

Explanation: The or operator is used for logical disjunction. The correct code is result = a or not b.

Question 42: What is the result of the following expression?


not (True or False) and False
  1. True
  2. False
  3. None
  4. 0

Answer: b) False

Explanation: True or False evaluates to True. not True evaluates to False. False and False evaluates to False.

Question 43: Which of the following expressions is False?

  1. not (False or True)
  2. True and not False
  3. False or True
  4. not (True and False)

Answer: a) not (False or True)

Explanation: False or True evaluates to True, and not True evaluates to False.

Question 44: Which of the following statements about Boolean operator precedence are true? (Select all that apply).

  1. not has higher precedence than and.
  2. and has higher precedence than or.
  3. or has higher precedence than not.
  4. not has the lowest precedence among Boolean operators.

Answer: a) not has higher precedence than and., b) and has higher precedence than or.

Explanation: not has higher precedence than and and or. and has higher precedence than or.

Question 45: What are the results of the following code? (Select all that apply).

a = True and not False
b = False or not True
c = not (True and False)
  1. a is True
  2. b is False
  3. c is True
  4. a is False

Answer: a) a is True, b) b is False, c) c is True

Explanation: a = True and not False evaluates to True. b = False or not True evaluates to False. c = not (True and False) evaluates to True.

Question 46: The ______ operator is evaluated before the and operator.

Answer: not

Explanation: The not operator has higher precedence than the and operator.

Question 47: The expression True or False and not True is evaluated by performing the ______ operation first.

Answer: not

Explanation: According to operator precedence, not is performed before and and or.

Question 48: Sort the following operations to correctly evaluate not True or False and True: not True, False and True, False or True.

Answer:

  • not True (result: False)
  • False and True (result: False)
  • False or False (result: False)

Explanation: The results of the operations are evaluated in the order of their precedence: not, and, and or.

Question 49: Sort the following expressions in descending order of their results: True and False, not (False or True), False or True, not (True and False).

Answer: a) a is True, b) b is False, c) c is True

  • False or True (result: True)
  • not (True and False) (result: True)
  • not (False or True) (result: False)
  • True and False (result: False)

Explanation: The results of the operations are True, True, False, and False respectively when evaluated correctly.

Question 50: Fill in the missing code to correctly compute the result of not (True or False).

result = not (True ______ False)

Answer: or

Explanation: The or operator is used for logical disjunction. The correct code is result = not (True or False).

Question 51: Fill in the missing code to correctly compute the result of True and not False or True.


result = True and not False ______ True

Answer: or

Explanation: The or operator is used for logical disjunction. The correct code is result = True and not False or True.

Question 52: Insert the correct operator to evaluate not (a or b) where a = False and b = True.


a = False
b = True
result = not (a ______ b)

Answer: or

Explanation: The or operator is used for logical disjunction. The correct code is result = not (a or b).

Question 52: Insert the correct operator to evaluate a and not b where a = True and b = False.

a = True
b = False
result = a ______ not b

Answer: and

Explanation: The and operator is used for logical conjunction. The correct code is result = a and not b.



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://w3resource.com/python/certificate/operators-and-data-types-boolean-operators-not-and-or.php