Exam4Training

What is the expected output of the following code if the user enters 2 and 4?

What is the expected output of the following code if the user enters 2 and 4?

x = input()

y = input()

print(x + y)
A . 4
B. 6
C. 24
D. 2

Answer: C

Explanation:

Topics: input() plus operator string concatenation

Try it yourself:

# x = input()

# y = input()

x, y = ‘2’, ‘4’ # Just for convenience

print(x + y) # 24

As always the input() function return a string.

Therefore string concatenation takes place and the result is the string 24

Exit mobile version