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

What is the expected output of the following code?
x = 4.5
y = 2
print(x // y)

Answer options

Correct answer: D

Explanation

The output of the code is determined by the floor division operator '//' in Python, which divides and rounds down to the nearest whole number. In this case, 4.5 divided by 2 equals 2.25, and the floor division results in 2.0. Options A, B, and C provide incorrect results as they do not account for the floor division operation.