Certified Entry-Level Python Programmer (PCEP-30-02) — Question 23

What is the expected output of the following code?
x = 2
y = 6
x += 2 ** 3
x //= y // 2 // 3
print(x)

Answer options

Correct answer: B

Explanation

The correct answer is B. In the code, x is initially set to 2 and then incremented by 2 raised to the power of 3, which results in 10. The expression for y is divided down to 1, so x divided by 1 remains 10. The other options are incorrect as they do not reflect the calculations performed in the code.