ProgrammingVery hardProduct-company MCQ pattern
What is printed?
What is printed?
from decimal import Decimal
print(Decimal('0.1') + Decimal('0.2') == Decimal('0.3'), Decimal(0.1) == Decimal('0.1'), float(Decimal('0.1') + Decimal('0.2')))- A. False False 0.3
- B. True False 0.3
- C. True True 0.3
- D. True False 0.30000000000000004
Correct answer: B. True False 0.3
Decimal arithmetic is exact in base 10, so the sum equals 0.3 exactly. Decimal(0.1) captures the binary value of the float, which is not exactly 0.1.
More Python Programming questions
- What is printed? python from fractions import Fraction print(Fraction(1, 3) + Fraction(1, 6), Fraction(0.5), Fraction('0.1') +…
- What is printed? python print(int('0b101', 0), int('0o17', 8), int('z', 36), int('-0'), int('+7'))
- What is printed? python print(str(True) + str(1 == 1.0), True + True, '3' True, [0] True)
- What is printed? python print(max('apple', 'banana', key=len), max('pear', 'fig', key=len), min('bb', 'aa', 'c', key=len))
- What is printed? python print('ab'.startswith(('x', 'a')), 'abc'.endswith('', 3), 'abc'.index('c', -1), 'aXbX'.split('X', 1))
- What is printed? python print(ord('A') + 1, chr(ord('a') + 25), chr(0x1F600) == 'U0001F600', len('U0001F600'), 'N{SNOWMAN}')