0
Couldn't understand this challenge
hello def recur(n): if n == 0: return 0 else: return n + recur(n -1) print(recur(3)) the output is 6 how they got 6!? thank you
4 odpowiedzi
+ 14
it's a recursive function
eventually it lined up to:
recur(3)
3 + recur(2)
2 + recur(1)
1 + recur(0)
this last recur call returns 0
so sum up all the n's as: 3 + 2 + 1 and there you have it ;)
6 it is
+ 11
recursion takes a bit to get used to
we've all been there ~_~
+ 2
thank you so much it's new for me.
+ 1
are you adding the numbers on the left .. or the parenthesis? I'm guessing the former, but better to ask than assume. :) thanks in advance