ProgrammingHardTCS NQT · Accenture
What is printed?
What is printed?
def sigma(n):
return sum(d for d in range(1, n + 1) if n % d == 0)
perfect = [n for n in range(2, 30) if sigma(n) == 2 * n]
print(perfect)- A. [6, 28, 496]
- B. [6]
- C. [6, 28]
- D. [6, 12, 28]
Correct answer: C. [6, 28]
A perfect number equals the sum of its divisors excluding itself, and below 30 only 6 and 28 qualify. The range stops before 30, so 496 never appears.
More Python Programming questions
- What is printed? python def phi(n): res, p = n, 2 while p p <= n: if n % p == 0: while n % p == 0: n //= p res -= res // p p += 1 if n >…
- What is printed? python def cntinc(a, k): dp = [[0] (k + 1) for in range(len(a))] for i in range(len(a)): dp[i][1] = 1 for j in range(i)…
- What is printed? python from itertools import count, islice print(list(zip('abc', count(10, 5))), list(islice(count(1, 2), 3)))
- What is printed? python d = {k: v for k, v in [('a', 1), ('b', 2), ('a', 3)] if v > 1} print(d, {v: k for k, v in d.items()})
- What is printed? python first, mid, last = [1, 2, 3, 4, 5] a, (b, c) = 1, (2, 3, 4) print(mid, last, b, c)
- What is printed? python def ack(m, n): if m == 0: return n + 1 if n == 0: return ack(m - 1, 1) return ack(m - 1, ack(m, n - 1))…