ProgrammingVery hardTCS NQT · Accenture
What is printed?
What is printed?
print(sum([1] * 10**5) == 10**5, sum([0.5] * 10**5) == 5e4, 1/3 + 1/3 + 1/3 == 1.0, 0.7 + 0.2 + 0.1 == 1.0)
- A. True True False True
- B. True False True False
- C. False True True False
- D. True True True False
Correct answer: D. True True True False
Exact fractions like 1/3 added three times give exactly 1.0, and integers add without error. But 0.1 + 0.2 is already 0.30000000000000004, and adding 0.7 leaves the sum just above 1.
More Python Programming questions
- What is printed? python from fractions import Fraction print(Fraction(7, 3) > 2, float(Fraction(7, 3)), Fraction(7, 3) // 1, Fraction(-7…
- What is printed? python print(1 + 2 3 2 // 4 % 5, (1 + 2) 3 2 // 4 % 5, -2 2, (-2) 2)
- What is printed? python print(max('zebra', 'Zebra'), min('zebra', 'Zebra'), 'apple' > 'Apple', 'Z' < 'a')
- What is printed? python x = 5 print(x.add(3), (5).mod(-3), (-5).mod(3), int.floordiv(-5, 3))
- What is printed? python print('ab'.rjust(5, ''), 'ab'.ljust(5, '-'), 'ab'.center(5, '.'), 'ab'.center(6, '.'))
- What is printed? python print(f'{"x"!r}', '%s and %r' % ('x', 'x'), '{!s} {!r}'.format('x', 'x'))