PCEP Practice Question: Data Types, Variables, Basic I/O and Operators
Exhibit
num = "10.5" result = int(num) print(result)
Refer to the exhibit. What will happen when this code is executed?
⚠ Common exam trap
Python Institute often tests the distinction between ValueError and TypeError, trapping candidates who think a decimal string causes a TypeError when it actually raises a ValueError because the string is not a valid integer literal.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
Raises ValueError
The code attempts to convert the string '10.5' to an integer using int(). Since '10.5' contains a decimal point, it is not a valid integer literal; int() cannot parse it and raises a ValueError. The correct approach would be to first convert to float (float('10.5')) and then to int if needed.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
Prints 10.5
Why it's wrong here
int() would not produce a float.
- ✗
Prints 10
Why it's wrong here
int() does not truncate string with decimal.
- ✗
Raises TypeError
Why it's wrong here
Type mismatch is a ValueError, not TypeError.
- ✓
Raises ValueError
Why this is correct
int() expects integer representation.
Go deeper
Related to this question
About these practice questions
This PCEP question is part of Courseiva's 498-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. Learn why practice questions differ from exam dumps →
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
This PCEP practice question is part of Courseiva's free Python Institute certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the PCEP exam.