QUESTION IMAGE
Question
question: 7
what would this program print?
def mystery(num, pattern):
result = \\
for i in range(num):
result = result + pattern
return result
print(mystery(3, \<>\)
it doesnt print anything
<>
<> <>
<> <> <>
Step1: Analyze the function
The function mystery takes two parameters num and pattern. It initializes result as an empty string. Then, it has a for loop that runs num times. In each iteration, it concatenates pattern to result.
Step2: Substitute the values
Here, num = 3 and pattern = "<<>>".
- First iteration (
i = 0):result = "" + "<<>>" = "<<>>" - Second iteration (
i = 1):result = "<<>>" + "<<>>" = "<<>>><<>>" - Third iteration (
i = 2):result = "<<>>><<>>" + "<<>>" = "<<>>><<>>><<>>"
Snap & solve any problem in the app
Get step-by-step solutions on Sovi AI
Photo-based solutions with guided steps
Explore more problems and detailed explanations
<<>>><<>>><<>>