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)
- A.15
- B.123Correct answer
- C.12 3
- 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
- In Python's interactive mode, what does the prompt >>> generally indicate?
- Explain the difference between a syntax error and a runtime error in Python, and give one example of each.
- Which of the following is a valid Python identifier?
- What is the output of the following Python code? x = 7 y = 2 print(x // y, x % y)
Practise more Computer Science
Sign up free for adaptive practice on this chapter, with instant feedback and hints on every question.
Start practising freeFree to start · No credit card needed