$ ./guess_the_languageProblem Solving — predict the output
Problem Solving — predict the output · hard · #122

What is printed?

def f(n, acc=0):
    if n == 0: return acc
    return f(n - 1, acc + n)
print(f(4))
  1. 10
  2. 4
  3. 0
  4. 24
The accumulator sums 4+3+2+1 before the base case returns it.
Play Problem Solving ▸