ProgrammingVery hardTCS NQT · Accenture
What is printed?
What is printed?
print(-1 ** 2, (-1) ** 2, -1 ** -1, (-1) ** -1)
- A. -1.5 -1 -1.0 -1.0
- B. -1 1 -1 -1
- C. -1 1 -1.0 -1.0
- D. -1 1 1.0 2.0
Correct answer: C. -1 1 -1.0 -1.0
The unary minus applies after **, so -1 ** 2 is -1. (-1) ** 2 is 1, and a negative exponent gives a float, so -1 ** -1 is -(1.0) and (-1) ** -1 is -1.0.
More Python Programming questions
- What is printed? python print(divmod(-9, 4), divmod(9, -4), -9 % 4, 9 % -4)
- What is printed? python class C: k = 10 try: a = [k + x for x in range(3)] except NameError: a = 'NameError' print(C.a)
- What is printed? python a = [1, 2, 3, 4] a[1:3] = [9] print(a) b = [1, 2, 3, 4] try: b[::2] = [0] except ValueError: print('ValueError')
- What is printed? python from collections import Counter def ways(a, t): dp = Counter({0: 1}) for x in a: nd = Counter(dp) for s, c in…
- What is printed? python print(bin(5 ^ 3), int('101', 2) << 2, ~5, -~5)
- What is printed? python import math print(math.prod([]), math.prod([2, 3.0]))