w3resource

PCEP-30-02 Exam Prep: In-Depth Practice on Relational 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 relational operators (==, !=, >, >=, <, <=). This diverse set of interactions enhances understanding and prepares for the PCEP-30-02 examination.

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

5 == 5
  1. True
  2. False
  3. None
  4. 0

Answer: a) True

Explanation: The == operator checks for equality. Since 5 is equal to 5, the result is True.

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

10 != 5
  1. True
  2. False
  3. None
  4. 0

Answer: a) True

Explanation: The != operator checks for inequality. Since 10 is not equal to 5, the result is True.

Question 3: Which of the following relational expressions is False?

  1. 8 > 3
  2. 4 >= 4
  3. 7 < 2
  4. 9 <= 10

Answer: c) 7 < 2

Explanation: The < operator checks if the left operand is less than the right operand. Since 7 is not less than 2, the result is False.

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

  1. 3 <= 3
  2. 5 != 5
  3. 8 > 2
  4. 7 == 7

Answer: a) 3 <= 3, c) 8 > 2, d) 7 == 7

Explanation: 3 <= 3 is True, 8 > 2 is True, and 7 == 7 is True.

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

  1. 10 == 10
  2. 6 != 6
  3. 2 > 3
  4. 4 <= 1

Answer:b) 6 != 6, c) 2 > 3, d) 4 <= 1

Explanation: 6 != 6 is False, 2 > 3 is False, and 4 <= 1 is False.

Question 6: Place the following relational operators in the correct order of their typical usage: ==, >, <=.

  1. ==
  2. <=
  3. >

Answer:

  1. ==
  2. >
  3. <=

Explanation: In relational expressions, == is used to check for equality, > is used to check if the left operand is greater than the right operand, and <= is used to check if the left operand is less than or equal to the right operand.

Question 7: Arrange the following relational expressions to evaluate the expression x = 5 > 3 and 2 == 2 correctly: 5 > 3, x = y and 2 == 2, y = 5 > 3.

Answer:

  1. 5 > 3 (evaluates to True)
  2. y = 5 > 3 (evaluates to True)
  3. x = y and 2 == 2 (evaluates to True)

Explanation: First, evaluate 5 > 3 to get True. Then, use y = True and evaluate x = y and 2 == 2 to get True.

Question 8: The operator that checks for inequality is ______.

Answer: !=

Explanation: The != operator checks if the two operands are not equal.

Question 9: The expression 7 >= 7 is evaluated by performing the ______ operation.

Answer: >=

Explanation: The >= operator checks if the left operand is greater than or equal to the right operand.

Question 10: Sort the following operations to correctly evaluate 3 <= 4 and 5 == 5: 3 <= 4, 5 == 5, True and True.

Answer:

  1. 3 <= 4 (result: True)
  2. 5 == 5 (result: True)
  3. True and True (result: True)

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

Question 11: Sort the following expressions in ascending order of their results: 6 != 7, 4 == 4, 3 < 2, 5 >= 5.

Answer:

  • 3 < 2 (result: False)
  • 6 != 7 (result: True)
  • 4 == 4 (result: True)
  • 5 >= 5 (result: True)

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

Question 12: Fill in the missing code to correctly compute the result of 4 < 5 and 6 >= 6.

result = 4 ______ 5 and 6 ______ 6

Answer: <, >=

Explanation: The < operator checks if the left operand is less than the right operand. The >= operator checks if the left operand is greater than or equal to the right operand. The correct code is result = 4 < 5 and 6 >= 6.

Question 13: Fill in the missing code to correctly compute the result of 7 != 8 or 9 == 10.

result = 7 ______ 8 or 9 ______ 10

Answer: !=, ==

Explanation: The != operator checks for inequality. The == operator checks for equality. The correct code is result = 7 != 8 or 9 == 10.

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

a = 1
b = 2
result = not (a ______ b)

Answer: ==

Explanation: The == operator checks for equality. The correct code is result = not (a == b).

Question 15: Insert the correct operator to evaluate a != b where a = 3 and b = 4.

a = 3
b = 4
result = a ______ b

Answer: !=

Explanation: The != operator checks for inequality. The correct code is result = a != b.

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

5 < 10
  1. True
  2. False
  3. None
  4. 0

Answer: a) True

Explanation: The < operator checks if the left operand is less than the right operand. Since 5 is less than 10, the result is True.

Question 17: Which of the following expressions is True?

  1. 10 <= 10
  2. 5 == 6
  3. 8 != 8
  4. 3 > 7

Answer: a) 10 <= 10

Explanation: The <= operator checks if the left operand is less than or equal to the right operand. Since 10 is equal to 10, the result is True.

Question 18: Which of the following statements about relational operators are true? (Select all that apply)

  1. == checks for equality.
  2. != checks for inequality.
  3. > checks if the left operand is greater than or equal to the right operand.
  4. <= checks if the left operand is less than or equal to the right operand.

Answer: a) == checks for equality., b) != checks for inequality., d) <= checks if the left operand is less than or equal to the right operand.

Explanation: == checks for equality, != checks for inequality, and <= checks if the left operand is less than or equal to the right operand.

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

a = 3 >= 2
b = 4 == 4
c = 5 < 3
 
  1. a is True
  2. b is True
  3. c is False
  4. c is True

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

Explanation: 3 >= 2 is True, 4 == 4 is True, and 5 < 3 is False.

Question 20: Arrange the following relational operators in order of their typical usage: !=, <=, >.

  1. !=
  2. <=
  3. >

Answer:

  1. !=
  2. >
  3. <=

Explanation: In relational expressions, != is used to check for inequality, > is used to check if the left operand is greater than the right operand, and <= is used to check if the left operand is less than or equal to the right operand.

Question 21: Arrange the following relational expressions to evaluate the expression x = 8 >= 7 and 3 != 2 correctly: 8 >= 7, x = y and 3 != 2, y = 8 >= 7.

Answer:

  1. y = 8 >= 7 (evaluates to True)
  2. 8 >= 7 (evaluates to True)
  3. x = y and 3 != 2 (evaluates to True)

Explanation: First, evaluate 8 >= 7 to get True. Then, use y = True and evaluate x = y and 3 != 2 to get True.

Question 22: The operator that checks if two values are equal is ______.

Answer: ==

Explanation: The == operator checks if the two operands are equal.

Question 23: The expression 7 <= 8 is evaluated by performing the ______ operation.

Answer: <=

Explanation: The <= operator checks if the left operand is less than or equal to the right operand.

Question 24: Sort the following operations to correctly evaluate 4 >= 3 and 5 == 5: 4 >= 3, 5 == 5, True and True.

Answer:

  1. 4 >= 3 (result: True)
  2. 5 == 5 (result: True)
  3. True and True (result: True)

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

Question 25: Sort the following expressions in ascending order of their results: 7 != 7, 6 == 6, 5 < 4, 9 >= 9.

Answer:

  • 5 < 4 (result: False)
  • 7 != 7 (result: False)
  • 6 == 6 (result: True)
  • 9 >= 9 (result: True)

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



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-relational-operators.php