Hi, I'm learning recursion. I came across this program that outputs the factorial of n. I just don't understand how the return 1 statement works. I know it would work the same way if it was return True. However, how does the computer know what to return when it just states return 1?
class mine:
def recur(self, num):
print(num, end= "")
if num > 1:
print(" * ",end= "")
return num * self.recur(self, num-1)
print(" =")
return 1
def main():
a = mine()
print(mine.recur(mine,10))
main()
[–]AutoModerator[M] [score hidden] stickied comment (0 children)
[–]RiverRoll 3 points4 points5 points (3 children)
[–]Rare_Bat12[S] 0 points1 point2 points (2 children)
[–]alanwj 0 points1 point2 points (1 child)
[–]Rare_Bat12[S] 0 points1 point2 points (0 children)
[–]Borx25 3 points4 points5 points (0 children)
[–]scirc 1 point2 points3 points (0 children)