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

What will be printed when the following Python code is executed and the user enters 12 on the first line and 3 on the second line? a = input() b = in…

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

hard · MCQ · Q-7F3F6F

What will be printed when the following Python code is executed and the user enters 12 on the first line and 3 on the second line? a = input() b = input() print(a + b)

  1. A.15
  2. B.123Correct answer
  3. C.12 3
  4. D.A TypeError is raised

Solution

The input() function returns data as a string. Therefore, a + b concatenates the strings "12" and "3", producing 123.

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