ProgrammingModerateTCS NQT · Wipro pattern
What is printed?
What is printed?
def dsum(n):
return n if n < 10 else dsum(sum(map(int, str(n))))
print(dsum(9875), dsum(0), dsum(999999999999))- A. 2 0 3
- B. 29 0 9
- C. 2 1 9
- D. 2 0 9
Correct answer: D. 2 0 9
Repeated digit sums give the digital root. 9875 leads to 2, 0 stays 0, and twelve nines give 108 and then 9.
More Python Programming questions
- What is printed? python def lcp(words): out = [] for col in zip(words): if len(set(col)) == 1: out.append(col[0]) else: break return…
- What is printed? python s = 'abc' 2 + 'd' print(s[::3], 'bcd' in s, s.index('c', 3))
- What is printed? python print(range(0, 10, 3) == range(0, 11, 3), range(0, 10, 3)[-1], len(range(1018)))
- What is printed? python s = 'abc' t = s s += 'd' u = list('abc') v = u u += ['d'] print(s, t, u is v, v)
- What is printed? python print(bin(0b1011011).count('1'), (0b1011011).bitcount(), 0b1011011 & (0b1011011 - 1))
- What is printed? python def f(n): c = 0 while n: n &= n - 1 c += 1 return c print(f(255), f(-1 & 0xFF), f(0))