PCEP PCEP Numeric Types and Arithmetic 1 — Questions and Answers
Question 1: What is the result of `7 // 2` in Python?
- 3 (Correct answer)
- 3.5
- 4
- 2
Correct answer: 3
`//` is floor division, which divides and rounds down to the nearest integer, giving 3.
Question 2: Which Python function converts a string to an integer?
- int() (Correct answer)
- str()
- float()
- num()
Correct answer: int()
`int()` converts a numeric string or float to an integer, truncating any decimal part.
Question 3: What is the output of `type(3.0)`?
- <class 'float'> (Correct answer)
- <class 'int'>
- <class 'double'>
- <class 'num'>
Correct answer: <class 'float'>
`3.0` is a floating-point literal, so `type()` returns `<class 'float'>`.
Question 4: What does the `%` operator do in Python arithmetic?
- Returns the remainder of division (Correct answer)
- Returns the quotient
- Raises to a power
- Performs floor division
Correct answer: Returns the remainder of division
The `%` modulo operator returns the remainder after dividing the left operand by the right.
Question 5: What is the result of `2 ** 3` in Python?
- 8 (Correct answer)
- 6
- 9
- 23
Correct answer: 8
`**` is the exponentiation operator; `2 ** 3` means 2 raised to the power of 3, which is 8.
Question 6: What is the value of `round(3.567, 2)`?
- 3.57 (Correct answer)
- 3.56
- 3.6
- 4.0
Correct answer: 3.57
`round(3.567, 2)` rounds to 2 decimal places; since the third decimal is 7 ≥ 5, it rounds up to 3.57.
What is the result of `7 // 2` in Python?