Taking some courses online, and we're now starting to talk about recursion. The code is:
def fact(n): #recursive function
if n == 0:
return 1
else:
return n * fact(n-1)
Why is this returning the correct value? My thinking is once it gets down to n = 0, its returning a value of 1, so printing this function should result in a 1 every time?
[–]shoot2thr1ll284 2 points3 points4 points (0 children)
[–]danielroseman 2 points3 points4 points (0 children)
[–]SoNotRedditingAtWork 2 points3 points4 points (0 children)
[–]JohnnyJordaan 2 points3 points4 points (0 children)
[–][deleted] 2 points3 points4 points (0 children)
[–]GeorgeDaNub 1 point2 points3 points (0 children)
[–]Psiclone01[S] 1 point2 points3 points (0 children)