ProgrammingVery hardTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
from functools import partial
def power(base, exp):
return base ** exp
sq = partial(power, exp=2)
cube_of_three = partial(power, 3)
print(sq(7), cube_of_three(2), sq(base=5))- A. 49 8 25
- B. 49 9 Error
- C. 7 9 25
- D. 49 9 25
Correct answer: D. 49 9 25
partial(power, exp=2) fixes the keyword exp, so sq(7) is 7**2. partial(power, 3) fixes base = 3 positionally, so cube_of_three(2) is 3**2 = 9. sq(base=5) passes base by keyword, giving 25.
More Python Programming questions
- What is printed? python import itertools it = itertools.count(10, 5) print(list(itertools.islice(it, 3)), next(it))
- What is printed? python words = ['b', 'a', 'c'] pairs = list(zip(sorted(words), range(10, 13))) print(pairs, dict(pairs)['c']…
- What is printed? python s = 'aabbbc' out = [] i = 0 while i < len(s): j = i while j < len(s) and s[j] == s[i]: j += 1 out.append(s[i] +…
- What is printed? python import math print(math.comb(10, 3) % 7, math.perm(5, 2), math.factorial(5) // math.factorial(3))
- What is printed? python x = [1, 2, 3] it = iter(x) print(next(it), sum(it), list(it))
- What is printed? python def tri(n): return n (n + 1) // 2 print(tri(10), tri(0), [tri(k) for k in range(4)])