ProgrammingHardGATE CS · Product-company placement
What is printed?
What is printed?
print(0.1 + 0.2 + 0.3 == 0.6, 0.3 + 0.2 + 0.1 == 0.6, 0.1 + (0.2 + 0.3) == 0.6)
- A. False True True
- B. True True True
- C. False False True
- D. False True False
Correct answer: A. False True True
Floating-point addition is not associative, so the grouping and order change the rounding error. Here (0.1 + 0.2) + 0.3 misses 0.6, while the other two groupings land exactly on it.
More Python Programming questions
- What is printed? python from decimal import Decimal print(Decimal('0.1') + Decimal('0.2') == Decimal('0.3'), Decimal(0.1) ==…
- 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))