निम्नलिखित प्रोग्राम का आउटपुट क्या है?
What is the output of the following program ?
print 0.1+0.2==0.3
A)
B)
C)
D)
Explanation:
Let's analyze the given Python program:
print 0.1 + 0.2 == 0.3
Explanation:
- In Python, floating-point numbers like
0.1
,0.2
, and0.3
cannot always be represented precisely due to the way floating-point arithmetic works in computers. - When you compute
0.1 + 0.2
, it may result in a value slightly different from0.3
because of precision errors in floating-point representation.
Specifically:
0.1 + 0.2
results in0.30000000000000004
, which is not exactly equal to0.3
.
Thus, the expression 0.1 + 0.2 == 0.3
evaluates to False
.
Output:
(B) False