Data Structures & AlgorithmsModerateTCS NQT Digital · Python semantics
Problem: What does the following print?
Problem: What does the following print?
print(int('0b101', 0), int('101', 2), 7 // 2 * 2)- A. 5 5 7
- B. 0 5 6
- C. 5 101 6
- D. 5 5 6
Correct answer: D. 5 5 6
int with base 0 honours the 0b prefix, and 7 // 2 * 2 = 3 * 2 = 6 because floor division binds before the multiplication's result is taken.
More Coding Interview Problems questions
- Problem: What does the following print? python fs = [lambda: i for i in range(3)] print([f() for f in fs])
- Problem: What does the following print? python print(len({1, 2, 3} & {2, 3, 4} | {5}))
- Problem: What does the following print? python print('10' < '9', 10 < 9)
- Problem: What does the following print? python print(int('12', 8) + int('0x1f', 16))
- Problem: How many strings of length 4 over {a, b} contain neither 'aa' nor 'bb' as a substring? Run the code. python from itertools import…
- Problem: What is the sum of Euler's totient phi(k) for k = 1 to 20? Run the code. python from math import gcd print(sum(sum(1 for g in…