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
- True
- False
- None
- 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)
- True
- False
- None
- 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?
- False and True
- not (True or True)
- True or False
- 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)
- not False
- True and not False
- False or not True
- 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)
- not True
- True and False
- False or False
- 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:
- not False (result: True)
- True and False (result: False)
- 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
- True
- False
- None
- 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?
- not (False or True)
- True and not False
- False or True
- 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)
- not has higher precedence than and.
- and has higher precedence than or.
- or has higher precedence than not.
- 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)
- a is True
- b is False
- c is True
- 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:
- 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 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)
- True
- False
- None
- 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
- True
- False
- None
- 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?
- not True and False
- not (True or False)
- not (False or False)
- 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).
- not (False and True)
- True or not False
- False and not False
- 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)
- True and not False
- not (True and False)
- False or not True
- 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:
- not (True and False) (evaluates to True)
- True or False and False (evaluates to True)
- 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:
- y = False or True (evaluates to True)
- not (False or True) (evaluates to False)
- 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:
- not False (result: True)
- True and False (result: False)
- 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:
- 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 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
- True
- False
- None
- 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?
- not (False or True)
- True and not False
- False or True
- 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).
- not has higher precedence than and.
- and has higher precedence than or.
- or has higher precedence than not.
- 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)
- a is True
- b is False
- c is True
- 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.
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
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics