nerdexam
Python_Institute

PCEP-30-02 · Question #62

What is the expected output of the following code? x = 1 // 5 + 1 / 5 print(x)

The correct answer is B. 0.2. Option B is correct because Python evaluates 1 // 5 as floor division, yielding the integer 0, and 1 / 5 as true division, yielding the float 0.2; adding them gives 0 + 0.2 = 0.2. Option A (0) is wrong because it ignores the / 5 term entirely or assumes both operators are floor…

Question

What is the expected output of the following code? x = 1 // 5 + 1 / 5 print(x)

Options

  • A0
  • B0.2
  • C0.0
  • D0.4

How the community answered

(23 responses)
  • A
    9% (2)
  • B
    74% (17)
  • C
    13% (3)
  • D
    4% (1)

Explanation

Option B is correct because Python evaluates 1 // 5 as floor division, yielding the integer 0, and 1 / 5 as true division, yielding the float 0.2; adding them gives 0 + 0.2 = 0.2. Option A (0) is wrong because it ignores the / 5 term entirely or assumes both operators are floor division. Option C (0.0) is wrong because while 0 is the floor-division result, the true-division term contributes 0.2, making the sum non-zero. Option D (0.4) is wrong because it treats // as regular division, effectively computing 0.2 + 0.2.

Memory tip: Think of // as "floor it" (drop the decimal, round down) and / as "full divide" (keep the decimal) - when they appear in the same expression, Python quietly promotes the result to float, so you always get a decimal answer.

Community Discussion

No community discussion yet for this question.

Full PCEP-30-02 Practice