Question Detail

COS 102 Python strings Objective Question

Question

Which of the following code snippets will result in the output "Ha! Ha! Ha! "?
Options
A <code>print("Ha! " + 3)</code>
B <code>print("Ha! " * "3")</code>
C <code>print("Ha! " * 3)</code>
Correct Answer
D <code>print("Ha! ", "Ha! ", "Ha! ")</code>
Correct Answer

Option C is the correct answer.

Detailed Explanation

The repetition operator '*' multiplies a string by an integer to create multiple copies. Option C correctly uses this syntax. Options A and B would result in errors, and D would print with default separator spaces.

Hint

Recall the example shown in the 'Repetition' section.

Question Info