निम्नलिखित प्रोग्राम का आउटपुट क्या है?
What is the output of the following program ?
print 0.1+0.2==0.3 A
True
B
False
C
Machine dependent
D
Error
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.3cannot 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.3because of precision errors in floating-point representation.
Specifically:
0.1 + 0.2results in0.30000000000000004, which is not exactly equal to0.3.
Thus, the expression 0.1 + 0.2 == 0.3 evaluates to False.
Output:
(B) False
यह फ्लोटिंग-पॉइंट अंकगणित की सीमा के कारण होता है। बाइनरी में $0.1$ और $0.2$ को सटीक रूप से नहीं दर्शाया जा सकता, जिससे $0.1 + 0.2$ का मान लगभग $0.30000000000000004$ आता है।
Correct Answer: B) False