Question 3
Back to Exercise
What is the output of the following Python program?
def show(n):
if n == 0:
return
show(n - 1)
print(n, end=" ")
show(4)
print()
- A 4 3 2 1
- B 0 1 2 3 4
- C 4
- D 1 2 3 4 Correct
Correct Answer: Option D
The print happens after the deeper call returns, so the innermost call (n = 1) prints first.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!