PCEP PCEP Numeric Types and Arithmetic 2 — Questions and Answers
Question 1: What is the output of `abs(-15)`?
- 15 (Correct answer)
- -15
- 0
- Error
Correct answer: 15
`abs()` returns the absolute value of a number, which is always non-negative.
Question 2: Which of the following is a valid Python complex number literal?
- 3+4j (Correct answer)
- 3+4i
- complex(3,4)
- 3i+4
Correct answer: 3+4j
Python uses `j` (not `i`) as the imaginary unit; `3+4j` is a valid complex literal.
Question 3: What does `int(3.9)` return?
- 3 (Correct answer)
- 4
- 3.9
- Error
Correct answer: 3
`int()` truncates toward zero, discarding the fractional part, so `int(3.9)` gives 3.
Question 4: What is the result of `10 % 3`?
- 1 (Correct answer)
- 3
- 0
- 2
Correct answer: 1
10 divided by 3 is 3 remainder 1, so the modulo operation returns 1.
Question 5: What is the output of `float('3.14')`?
- 3.14 (Correct answer)
- '3.14'
- 3
- Error
Correct answer: 3.14
`float()` converts a string representation of a decimal number to a float value.
Question 6: Which operator performs integer (floor) division in Python?
- // (Correct answer)
- /
- %
- **
Correct answer: //
`//` is the floor division operator; it divides and floors the result to the nearest integer.
What is the output of `abs(-15)`?