ProgrammingVery hardTCS NQT · Accenture
What is printed?
What is printed?
print(len(bin(255)), bin(255).count('0'), bin(-255).count('1'))- A. 10 2 8
- B. 10 1 8
- C. 9 1 8
- D. 10 1 9
Correct answer: B. 10 1 8
bin(255) is 0b11111111, which has ten characters. The only zero is inside the 0b prefix, and bin(-255) has eight ones after its minus sign.
More Python Programming questions
- What is printed? python print('%s' % 'x' 3, '%s' 2 % ('a', 'b'), '%s' % ('x' 3))
- What is printed? python print(3 'a' + 'b', 'c' 3 + 'd')
- What is printed? python print(int(3.7 10), int(0.7 10), 3.7 10 == 37, 0.7 10 == 7)
- What is printed? python print(sorted([True, 2, 1.5, False, -1]))
- What is printed? python print(1 if [] == [] is True else 0, [] is [], () is ())
- What is printed? python print(len(str(float(10300))), str(float(1022))[:4], float(1022) == 1022)