ProgrammingHardTCS NQT · Accenture
What is printed?
What is printed?
print(bin(5 ^ 3), bin(-5 & 0b1111), int('-0b101', 2))- A. 0b110 0b1011 -5
- B. 0b110 0b1011 -6
- C. 0b110 0b1111 -5
- D. 0b101 0b1011 -5
Correct answer: A. 0b110 0b1011 -5
5 xor 3 is 6, which is 0b110. -5 in four bits is 1011, and int() accepts a sign before a prefix that matches the base, so the result is -5.
More Python Programming questions
- What is printed? python print(2 -1, 2 -1074 > 0, 10 -3 == 0.001, 10 -2)
- What is printed? python print(' '.join(['a', '', 'b']), ' '.join([]) == '', '-'.join('abc'), 'x'.join(['1', '2', '3']))
- What is printed? python from functools import reduce print(reduce(lambda a, b: a + b, ['x', 'y', 'z'], ''), reduce(lambda a, b: a b…
- What is printed? python print(0.1 + 0.2 > 0.3, 0.3 - 0.1 == 0.2, 0.2 + 0.2 == 0.4, 0.4 - 0.2 == 0.2)
- What is printed? python from collections import defaultdict d = defaultdict(int) for w in 'a b a c'.split(): d[w] += 1…
- What is printed? python print(sum([1e100, 1.0, -1e100]) == 1.0, sum([1, 1e100, -1e100]), 1e100 + 1.0 - 1e100)