ProgrammingModerateTCS NQT · Infosys
What is printed?
What is printed?
print(1 / 2 + 1 // 2 + 1 % 2, 1 / 2 * 2 == 1, 3 * 1 / 2 == 3 * (1 / 2))
- A. 1.0 True True
- B. 1.5 False True
- C. 1.5 True False
- D. 1.5 True True
Correct answer: D. 1.5 True True
Multiplication and division run left to right, so 3 * 1 / 2 equals 3 * (1 / 2) because both evaluate 1.5 in float. The first value adds 0.5, 0 and 1 to get 1.5.
More Python Programming questions
- What is printed? python print(0x10 + 0o10 + 0b10, 10 + 0x1, 1e1 + 1, 1j 1j)
- What is printed? python print(max(-0.0, 0), min(0, -0.0), -0.0 + 0, 0 - 0.0)
- What is printed? python a = 10 b = 3 print(a / b b == a, a // b b + a % b == a, a % b / b == (a / b) % 1)
- What is printed? python print(7 % 3 2, (7 % 3) 2, -7 % 3 2, 2 3 2 % 4)
- What is printed? python print(len(' a b '.split()), len(' a b '.split(' ')), len('anbn'.splitlines()), len('anbn'.split('n')))
- What is printed? python print(list('abc'.encode()), 'abc'.encode()[0] + 1, bytes('hi', 'ascii') == b'hi')