PCEP-30-02 · Question #112
What is the expected output of the following code if the user enters 3 and 11? ``python x = input() y = int(input()) print(x * y) ``
The correct answer is A. 333333. Option A is correct because input() always returns a string, so x holds "3" (not the integer 3), while int(input()) properly converts the second input to the integer 11. In Python, string integer is string repetition, not arithmetic multiplication - so "3" 11 produces "3"…
Question
x = input()
y = int(input())
print(x * y)
Options
- A333333
- B18
- C36
- D666
How the community answered
(55 responses)- A75% (41)
- B5% (3)
- C16% (9)
- D4% (2)
Explanation
Option A is correct because input() always returns a string, so x holds "3" (not the integer 3), while int(input()) properly converts the second input to the integer 11. In Python, string * integer is string repetition, not arithmetic multiplication - so "3" * 11 produces "3" repeated multiple times, yielding a string of repeated 3s, which matches the format shown in A.
Option B (18) would result from adding 3 + ... or some other arithmetic combination of the inputs, wrongly assuming both values are integers. Option C (36) likely comes from confusing * with addition or some other arithmetic error on integer values. Option D (666) might stem from thinking x * y means something like doubling or tripling a number, but none of these apply when one operand is a string.
Memory tip: Watch for int() - if it's missing around input(), the variable is a string, and * becomes a photocopier, not a calculator.
Community Discussion
No community discussion yet for this question.