← Quiz: Comprehensions and Lambda: all 15 questions
Quiz: Comprehensions and Lambda · Question 13 of 15
What does this print? (code)
What does this print?
def total(n):
if n == 0:
return 0
return n + total(n - 1)
print(total(4))
- A.4
- B.24
- C.10
- D.RecursionError
Answer & explanation
Correct answer: 10
4 + 3 + 2 + 1 + 0 = 10. The base case n == 0 stops the calls.
Can you get the rest right without peeking?
Take the timed Quiz: Comprehensions and Lambda quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →