ProgrammingModerateTCS NQT · Infosys
What is printed?
What is printed?
x = 17 print(x.bit_length(), (x & -x).bit_length(), x.bit_count(), bin(x)[2:].zfill(8))
- A. 5 1 2 10001
- B. 5 2 2 00010001
- C. 5 1 2 00010001
- D. 4 1 2 00010001
Correct answer: C. 5 1 2 00010001
17 is 10001 in binary, so it needs five bits and has two set bits. Its lowest set bit is 1, which needs one bit, and zfill pads the eight-digit form with a leading zero.
More Python Programming questions
- What is printed? python print(int(2.5 4) // 3, int(10 / 4 2), 10 // 4 2, 10 / 4 // 2)
- What is printed? python print(float(1) / 3 + float(2) / 3 == 1.0, 0.1 0.1 100 == 1.0, 1 - 0.1 9 == 0.1)
- What is printed? python print(f"{0.1:.20f}")
- What is printed? python def nge(a): st, res = [], [-1] len(a) for i, x in enumerate(a): while st and a[st[-1]] < x: res[st.pop()] = x…
- What is printed? python from itertools import takewhile, dropwhile a = [1, 3, 4, 6, 7, 9] print(list(takewhile(lambda x: x % 2, a))…
- What is printed? python def f(): try: return 'try' finally: print('finally', end=' ') print(f())