ProgrammingVery hardJEE Advanced · CAT placement
What is printed?
What is printed?
from decimal import Decimal
from fractions import Fraction
print(0.1 + 0.2 == 0.3, Decimal('0.1') + Decimal('0.2') == Decimal('0.3'), Decimal(0.1) == Decimal('0.1'), Fraction(1, 10) == 0.1)- A. False True False True
- B. False True True False
- C. True True False False
- D. False True False False
Correct answer: D. False True False False
Decimal('0.1') is exact, so decimal addition gives 0.3 exactly. Decimal(0.1) keeps the float's binary value, and a Fraction compares exactly with the float, which is not one tenth.
More Python Programming questions
- What is printed? python print(1e22, 1e21, 1e16, 1e15, 1e-5, 0.0001)
- What is printed? python print(int(1e16 + 1), 253 + 1 == float(253 + 1), float(253 + 1) == 253)
- What is printed? python print(pow(10, 18, 7), (-3) 3 % 7, pow(-3, 3, -7), -3 3 % 7)
- What is printed? python print('%.3s|%5.1s|' % ('abcdef', 'xyz'))
- What is printed? python print('straße'.casefold() == 'strasse', 'straße'.lower() == 'strasse', 'Straße'.casefold())
- What is printed? python print('x'.removeprefix('xx'), 'hello'.removesuffix('llo'), 'abc'.removeprefix(''))