ProgrammingHardTCS NQT · Accenture

What is printed?

What is printed?
print(7 // 2 * 2, 7 / 2 * 2, 2 ** 3 ** 2)
  1. A. 6 7.0 64
  2. B. 6 7 512
  3. C. 6 7.0 512
  4. D. 8 7.0 512

Correct answer: C. 6 7.0 512

// and * have the same precedence and run left to right, so 7 // 2 * 2 is 6. / always gives a float, and ** is right-associative, so 2 ** 3 ** 2 is 2 ** 9.

More Python Programming questions

Exams that ask this topic