Getting Started with Python · Class 11 · CBSE · Science Computer Science

What is the output of the following Python code? x = 7 y = 2 print(x // y, x % y)

Practice question from Getting Started with Python (Class 11 · CBSE · Science Computer Science), with the correct answer and a step-by-step solution.

medium · MCQ · Q-7D64CD

What is the output of the following Python code? x = 7 y = 2 print(x // y, x % y)

  1. A.3 1Correct answer
  2. B.3.5 1
  3. C.4 0
  4. D.3 0

Solution

The // operator performs floor division, so 7 // 2 gives 3. The % operator gives the remainder, so 7 % 2 gives 1.

More from Getting Started with Python

All of Getting Started with Python

Practise more Computer Science

Sign up free for adaptive practice on this chapter, with instant feedback and hints on every question.

Start practising free

Free to start · No credit card needed