ProgrammingHardTCS NQT · Wipro pattern
What is printed?
What is printed?
print(7 // 0.5, 7 % 0.5, 0.5 * 7 // 1, 1e308 * 10 == float('inf'))- A. 14 0 3 True
- B. 14.0 0.5 3.0 True
- C. 14.0 0.0 3.0 True
- D. 14.0 0.0 3.5 True
Correct answer: C. 14.0 0.0 3.0 True
Floor division with a float returns a float, so 7 // 0.5 is 14.0. 7 % 0.5 is exactly 0.0, and 0.5 * 7 is 3.5, which floors to 3.0. Overflowing a float multiplication gives infinity.
More Python Programming questions
- What is printed? python print(sum([True, True, False]), True 3, 'ab' True, [0] True)
- What is printed? python print('%x' % 255, '%X' % 255, '%#o' % 8, '%+d' % 0)
- What is printed? python print(float('1e-7'), 0.000001, 1e-6 == 0.000001, 123456789012345678.0)
- What is printed? python print(round(0.5 + 1), round(-0.5 - 1), round(2.5 - 0.0001))
- What is printed? python print(0.1 + 0.2 - 0.3, 0.3 - 0.1 - 0.2, 1 / 49 49, 1 / 10 10)
- What is printed? python import bisect a = [10, 9, 2, 5, 3, 7, 101, 18] tails = [] for x in a: i = bisect.bisectleft(tails, x) if i ==…