PCEP Practice Question: Data Types, Variables, Basic I/O and Operators
A developer runs the following code: x = 0.1; y = 0.2; print(x + y == 0.3). What is the output and why?
⚠ Common exam trap
Python Institute often tests the misconception that Python performs exact decimal arithmetic, leading candidates to expect True, when in fact the binary floating-point representation causes a small rounding error that makes the comparison False.
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
✓
False, due to floating-point precision
Floating-point numbers in Python (and most programming languages) are stored in binary (IEEE 754 double-precision), and values like 0.1 and 0.2 cannot be represented exactly. The sum 0.1 + 0.2 yields a result slightly greater than 0.3 (approximately 0.30000000000000004), so the equality comparison returns False.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
False, because the + operator is not defined for floats
Why it's wrong here
The + operator is defined for floats and performs binary addition; the failure is representational, not syntactic. This option would be correct only if the operands were incompatible types, such as adding a string to a float, which raises TypeError rather than returning False.
- ✗
True, because Python rounds to 0.3
Why it's wrong here
Python does not round binary floating-point results for equality; 0.1 + 0.2 yields 0.30000000000000004, so the comparison returns False. Rounding is applied only by explicit functions such as round(), which would be the answer if the code called round(x + y, 1).
- ✗
True, because Python uses decimal arithmetic
Why it's wrong here
Python's float type uses IEEE 754 binary64, not decimal arithmetic; the decimal module provides exact decimal representation but is not used here. Decimal arithmetic would be the answer if the code imported decimal and constructed Decimal('0.1') and Decimal('0.2').
- ✓
False, due to floating-point precision
Why this is correct
Binary floating-point cannot represent 0.1, 0.2 or 0.3 exactly, so their stored approximations sum to 0.30000000000000004 rather than 0.3. The equality test therefore returns False, satisfying the stem's requirement to explain the output of comparing x + y against 0.3.
Go deeper
Related to this question
About these practice questions
Courseiva writes every PCEP question from scratch — 482 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or 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.