0
Explanation
Hello everyone, Can someone please explain this piece of code for me. I thought the output was 16, but its 19. I just cant figure out why its 19. Can anyone explain why its 19? def test(i,j): If i == 0: return j else: return test(i-1, i+j) print(test(4,9))
1 Antwort
+ 5
Work your way down.
test(4, 9) # (4, 9)
== test(4-1, 4+9) # (3, 13)
== test(3-1, 13+3) # (2, 16)
== test(2-1, 16+2) # (1, 18)
== test(1-1, 18+1) # (0, 19)
== 19.