w3resource

Choosing and Using Numeric Operators for the PCEP-30-0x Exam

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 numeric operators: ** * / % // + –. This diverse set of interactions enhances understanding and prepares for the PCEP-30-02 examination.

Question 1: What is the result of the expression 5 ** 2?

  1. 10
  2. 25
  3. 7
  4. 20

Answer: b) 25

Explanation: The ** operator is the exponentiation operator, so 5 ** 2 is 5 raised to the power of 2, which equals 25.

Question 2: What is the result of the expression 10 // 3?

  1. 3.33
  2. 3
  3. 4
  4. 2

Answer: b) 3

Explanation: The // operator is the floor division operator, which returns the largest integer less than or equal to the division result. 10 // 3 equals 3.

Question 3: What is the result of the expression 8 % 3?

  1. 2
  2. 3
  3. 5
  4. 1

Answer: a) 2

Explanation: The % operator is the modulus operator, which returns the remainder of the division. 8 % 3 equals 2.

Question 4: Which of the following expressions will result in a value of 4? (Select all that apply).

  1. 2 * 2
  2. 8 / 2
  3. 2 + 2
  4. 16 // 4

Answer:a) 2 * 2, b) 8 / 2, c) 2 + 2, d) 16 // 4

Explanation: All of the given expressions evaluate to 4.

Question 5: Which of the following are valid numeric operators in Python? (Select all that apply).

  1. **
  2. *
  3. //
  4. &&

Answer: a) **, b) *, c) //

Explanation: The **, *, and // operators are valid numeric operators in Python. && is not a valid numeric operator in Python.

Question 6: Arrange the following operations in the order of their precedence: addition, multiplication, exponentiation, floor division.

Answer:

  • exponentiation
  • multiplication
  • floor division
  • addition

Explanation: According to operator precedence in Python, exponentiation has the highest precedence, followed by multiplication and floor division, and addition has the lowest precedence.

Question 7: Place the numeric operators in the correct order to make the expression 7 true: 5 _ 3 _ 2 _ 2 _ 4 _ 1 = 7.

Answer: 5 + 3 * 2 ** 2 / 4 - 1 = 7

Explanation: Let's break down the expression step by step according to the order of operations (PEMDAS/BODMAS):
Expression: 5+3×2^2÷4−1 Exponentiation (**):
Calculate 2^2: 2^2=4
Now the expression becomes: 5+3×4÷4−1
Multiplication (*) and Division (/):
Perform multiplication and division from left to right:
First, 3×4: 3×4=12
Then, 12÷4: 12÷4=3
Now the expression is: 5+3−1
1. Addition (+) and Subtraction (-):
Perform addition and subtraction from left to right:
First, 5+3: 5+3=8
Then, 8−1: 8−1=7
So, the result of the expression is 7.

Question 8: The expression 10 / 3 results in a ______.

Answer: float

Explanation: The / operator in Python always performs floating-point division, returning a float

Question 9: The operator used for exponentiation in Python is ______.

Answer: **

Explanation: The ** operator is used for exponentiation in Python.

Question 10: Sort the following operations by their precedence in Python: addition, modulus, exponentiation, multiplication.

Answer:

  • exponentiation
  • multiplication
  • modulus
  • addition

Explanation: According to Python's operator precedence, exponentiation is first, followed by multiplication, modulus, and then addition.

Question 11: Sort the following operations in descending order of their result for the expression 16: floor division by 3, multiplication by 2, modulus 5, subtraction of 10.

Answer:

  • Multiplication by 2 (Result: 32)
  • Subtraction of 10 (Result: 6)
  • Floor division by 3 (Result: 5)
  • Modulus 5 (Result: 1)

Explanation: The results are 32, 6, 5, and 1 respectively.

Question 12: Fill in the missing code to correctly perform exponentiation.

result = 4 ______ 2

Answer: **

Explanation: The ** operator is used for exponentiation in Python.

Question 13: Fill in the missing code to correctly perform floor division.

result = 15 ______ 4

Answer: //

Explanation: The // operator is used for floor division in Python.

Question 14: Insert the correct operator to perform modulus operation.

result = 10 ______ 3

Answer: %

Explanation: The % operator is used to find the remainder of the division in Python.

Question 15: Insert the correct operator to perform multiplication.

result = 6 ______ 7

Answer: *

Explanation: The * operator is used for multiplication in Python.

Question 16: What is the result of the expression 7 + 3 * 2?.

  1. 20
  2. 13
  3. 17
  4. 16

Answer: b) 13

Explanation: According to operator precedence, multiplication is performed before addition. So, 3 * 2 equals 6, and 7 + 6 equals 13.

Question 17: What will be the output of the following codeWhat is the result of the expression 14 // 4?

  1. 3.5
  2. 3
  3. 4
  4. 2

Answer: b) 3

Explanation: The // operator performs floor division, so 14 // 4 equals 3.

Question 18: Which of the following expressions evaluate to 0? (Select all that apply)

  1. 10 % 5
  2. 12 // 4 - 3
  3. 2 ** 3 - 6
  4. 9 - 9

Answer: a) 10 % 5, b) 12 // 4 - 3, d) 9 - 9

Explanation: The expressions 10 % 5, 12 // 4 - 3, and 9 - 9 all evaluate to 0.

Question 19: Which of the following are true about the + operator in Python? (Select all that apply)

  1. It can be used to add numbers
  2. It can be used to concatenate strings
  3. It can be used to multiply numbers
  4. It can be used to subtract numbers

Answer: a) It can be used to add numbers, b) It can be used to concatenate strings

Explanation: The + operator can be used to add numbers and concatenate strings. It cannot be used to multiply or subtract numbers.

Question 20: The result of the expression 3 ** 2 is ______.

Answer: 9

Explanation: 3 ** 2 is 3 raised to the power of 2, which equals 9.

Question 21: The result of the expression 7 % 4 is ______.

Answer: 3

Explanation: The % operator returns the remainder of the division. 7 % 4 equals 3.

Question 22: Sort the following operators by their precedence in ascending order: +, **, //, %.

Answer:

  • +
  • %
  • //
  • **

Explanation: According to Python's operator precedence, + has the lowest precedence, followed by %, //, and ** which has the highest precedence.

Question 23: Sort the following operations by their result for the expression 5: addition of 3, multiplication by 2, subtraction of 4, modulus 2.

Answer:

  • multiplication by 2 (10)
  • addition of 3 (8)
  • subtraction of 4 (1)
  • modulus 2 (1)

Explanation: The results are 10, 8, 1, and 1 respectively.

Question 24: Fill in the missing code to correctly perform subtraction.

result = 10 ______ 3

Answer: -

Explanation: The - operator is used for subtraction in Python.

Question 25: Fill in the missing code to correctly perform addition.

result = 5 ______ 7

Answer: +

Explanation: The + operator is used for addition in Python.

Question 26: Insert the correct operator to perform division.

result = 8 ______ 2

Answer: /

Explanation: The / operator is used for division in Python.

Question 27: Insert the correct operator to perform addition.

result = 4 ______ 6

Answer: +

Explanation: The + operator is used for addition in Python.



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