Certified Entry-Level Python Programmer (PCEP-30-02) — Question 38
The following code:
print(float("1, 3"))
Answer options
- A. prints 13
- B. prints 1.3
- C. prints 1,3
- D. raises a ValueError exception.
Correct answer: D
Explanation
The correct answer is D because the float() function cannot convert a string with a comma into a float, leading to a ValueError. Options A, B, and C are incorrect as they suggest valid outputs that would not occur with the given input.