ProgrammingVery hardTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
x = [0] * 3 x[0] += 1 x = x * 2 x[3] += 5 print(x)
- A. [1, 0, 5, 0, 0, 0]
- B. [1, 0, 0, 6, 0, 0]
- C. [1, 0, 0, 1, 0, 0]
- D. [1, 0, 0, 5, 0, 0]
Correct answer: B. [1, 0, 0, 6, 0, 0]
x becomes [1, 0, 0] and then [1, 0, 0, 1, 0, 0] after the multiplication. Index 3 is the first item of the second copy, which is 1, so adding 5 gives 6.
More Python Programming questions
- What is printed? python from collections import Counter c = Counter('aab') c.subtract('ab') print(c['a'], c['b'], sorted((+c).items()))
- What is printed? python n = 100 z, p = 0, 5 while p <= n: z += n // p p = 5 print(z, len(str(import('math').factorial(n)))…
- What is printed? python n, steps = 27, 0 while n != 1: n = n // 2 if n % 2 == 0 else 3 n + 1 steps += 1 print(steps, n)
- What is printed? python x, rev = 1200, 0 while x: rev = rev 10 + x % 10 x //= 10 print(rev, int(str(1200)[::-1]), str(1200)[::-1] == '0021')
- What is printed? python print(int('zz', 36), format(1295, 'x'), int('1295', 10) == 1295, int('zz', 36) == 35 36 + 35)
- What is printed? python print([n for n in range(100, 1000) if sum(int(d) 3 for d in str(n)) == n])