ProgrammingVery hardTCS NQT · Accenture
What is printed?
What is printed?
print(2 ** -1 * 2 ** 1, 2 ** -(1 * 2) ** 1, (2 ** -1) * (2 ** 1))
- A. 1 0.25 1
- B. 1.0 0.5 1.0
- C. 1 0.25 1.5
- D. 1.0 0.25 1.0
Correct answer: D. 1.0 0.25 1.0
Negative exponents give floats, so 2 ** -1 is 0.5 and the first product is 1.0. The unary minus in the exponent of the second expression applies to the whole power, giving 2 ** -2 = 0.25.
More Python Programming questions
- What is printed? python print('%-5s|%5s|' % ('ab', 'cd'), '%(x)d-%(y)s' % {'x': 1, 'y': 'z'})
- What is printed? python print(0.1 3 == 0.30000000000000004, 0.1 3 - 0.3 == 5.551115123125783e-17, 0.3 - 0.1 3 == -5.551115123125783e-17)
- What is printed? python print(len('ab' + 'c' 0), 'ab'[1:][0] 2, ('ab' 2)[::3])
- What is printed? python print(int(' 3 ') + 1, int('3n') 2, float(' 2.5t') 2)
- What is printed? python print(len('é'.encode('utf-8').decode('latin-1')), 'é'.encode('utf-8').decode('latin-1'))
- What is printed? python print(sum(1 for c in 'Mississippi' if c in 'aeiouAEIOU'), 'Mississippi'.lower().count('s')…