ProgrammingHardTCS NQT · Wipro pattern
What is printed?
What is printed?
x = 5 print(x // 2 * 2 == x, x / 2 * 2 == x, 5 / 2 == 2.5, 5 // 2.0 == 2)
- A. False True False True
- B. True True True True
- C. False True True True
- D. False False True True
Correct answer: C. False True True True
5 // 2 * 2 is 4, so the first comparison is False. Division by 2 is exact in binary here, so 5 / 2 * 2 is 5.0 and equals x. 5 // 2.0 is 2.0, which equals 2.
More Python Programming questions
- What is printed? python print(bytes('é', 'utf-8'), 'é'.encode('latin-1'), len('é'.encode('latin-1')) == len('é'.encode('utf-8')))
- What is printed? python print(round(-0.5), round(0.5), round(1.5), round(-1.5), round(2.5))
- What is printed? python x = [3, 1, 2] print(sorted(x, reverse=True)[:2], x[::-1][1:], list(reversed(sorted(x))))
- What is printed? python print('%08.2f' % -1.5, '%+08d' % 42, '%-+5d|' % 7, '%x' % -255)
- What is printed? python print(2 10 == 1024, 2 10 == 1 << 10, 10 2 3, (10 2) 3)
- What is printed? python from itertools import accumulate print(list(accumulate([1, 2, 3], lambda a, b: a b)), list(accumulate('ab'…