PCEP Type Conversion and Built-in Functions 2 — Questions and Answers
Question 1: What is the return value of len("Python")?
- 6 (Correct answer)
- 5
- 7
- 8
Correct answer: 6
len() counts characters in the string; "Python" has exactly 6 characters: P, y, t, h, o, n.
Question 2: What sequence does range(1, 6) generate in Python?
- Values 1, 2, 3, 4, 5, 6 (stop inclusive)
- Values 0, 1, 2, 3, 4, 5
- Values 1, 2, 3, 4, 5 (stop exclusive) (Correct answer)
- Values 0, 1, 2, 3, 4, 5, 6
Correct answer: Values 1, 2, 3, 4, 5 (stop exclusive)
range(start, stop) generates values from start up to but not including stop, so range(1, 6) produces 1, 2, 3, 4, 5.
Question 3: What does abs(-15) return in Python?
- -15
- 15 (Correct answer)
- 0
- 1
Correct answer: 15
abs() returns the absolute value of its argument, converting -15 to 15.
Question 4: What is the result of max(3, 7, 2, 9, 4)?
- 3
- 7
- 4
- 9 (Correct answer)
Correct answer: 9
max() compares all provided arguments and returns the largest, which is 9.
Question 5: What does min([10, 3, 7, 1, 5]) return?
- 3
- 10
- 1 (Correct answer)
- 5
Correct answer: 1
min() returns the smallest element in the iterable, which is 1 in this list.
Question 6: What does round(3.567, 1) return in Python?
- 3.6 (Correct answer)
- 3.5
- 4.0
- 3.57
Correct answer: 3.6
round(3.567, 1) rounds to 1 decimal place; since the second decimal is 6 (≥5), it rounds up to 3.6.
Question 7: What is the result of sum([1, 2, 3, 4, 5])?
- 10
- 15 (Correct answer)
- 12
- 54321
Correct answer: 15
sum() adds all elements in the iterable; 1+2+3+4+5 equals 15.
What is the return value of len("Python")?