ProgrammingHardTCS NQT · Infosys
What is printed?
What is printed?
x = 1 / 3 print(x * 3 == 1, 1 - 2 / 3 == 1 / 3, 0.1 + 0.2 - 0.3 == 0)
- A. True True False
- B. True False False
- C. False False True
- D. True False True
Correct answer: B. True False False
1/3 times 3 rounds to exactly 1.0. 2/3 is stored with rounding, so 1 - 2/3 is a different double from 1/3, and 0.1 + 0.2 - 0.3 is about 5.6e-17, not zero.
More Python Programming questions
- What is printed? python s = 'ab' 2 + 'c' print(s.count('ab'), s.count('aba'), s.find('b', 2), s.rfind('ab'), s.index('c'))
- What is printed? python print('abc'.partition('x'), 'a=b=c'.partition('='), 'a=b=c'.rpartition('='))
- What is printed? python s = 'abcdefgh' print(s[::-2], s[1::3], s[-3:-6:-1], s[::-1][::2])
- What is printed? python print('%05.1f|%x|%o|%e' % (3.14159, 255, 8, 12345.678))
- What is printed? python print(f'{-5:+}', f'{5:+}', f'{3.0:g}', f'{1e6:g}', f'{1e-5:g}', f'{123456789.0:g}')
- What is printed? python print(f'{12345678:,}', f'{0.5:.0%}', f'{2.5:.0f}', f'{3.5:.0f}', f'{-0.4:.0f}')