ProgrammingVery hardTCS NQT · Accenture

What is printed?

What is printed?
print(2 ** -1 * 2 ** 1, 2 ** -(1 * 2) ** 1, (2 ** -1) * (2 ** 1))
  1. A. 1 0.25 1
  2. B. 1.0 0.5 1.0
  3. C. 1 0.25 1.5
  4. 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

Exams that ask this topic