PCEP Practice Question: Data Types, Variables, Basic I/O and Operators
A program uses 'x = 3.14' and 'y = int(x)'. What is the value of y?
⚠ Common exam trap
Many exam-takers confuse int() with round() and assume it performs rounding to the nearest integer, leading them to choose option A (4) instead of the correct truncation result (3).
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
✓
3
The int() function in Python truncates the decimal part of a float, converting 3.14 to the integer 3. It does not round to the nearest whole number.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
4
Why it's wrong here
int() truncates the fractional part rather than rounding, so 3.14 becomes 3, not 4. It is tempting because rounding to the nearest integer is a common operation, but that requires round(), whereas int() simply discards everything after the decimal point.
- ✗
3.14
Why it's wrong here
int() truncates toward zero, returning the integer 3, so y cannot remain 3.14. It is tempting because the original float value is visible in the code, but assigning the converted result to y discards the fractional part entirely.
- ✗
Error
Why it's wrong here
int() accepts a float argument and truncates it toward zero without raising an exception, so no error occurs. It is tempting because int() rejects non-numeric strings, but a float such as 3.14 is a valid input, yielding 3.
- ✓
3
Why this is correct
Calling `int()` on a float truncates toward zero, discarding the fractional part rather than rounding to the nearest integer. For `x = 3.14`, the decimal `.14` is dropped, leaving exactly `3`. This satisfies the stem's requirement that `y` holds the integer conversion result of the float value.
Go deeper
Related to this question
About these practice questions
One of 482 original PCEP practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. 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.