fork download
  1. #
  2. # Recursive Factorial with accumulator
  3. #
  4. def fact(n, acc=1):
  5.  
  6. if n == 0:
  7. print(n,end=" ")
  8. return acc
  9.  
  10. else:
  11. print(n,end=" ")
  12. return fact(n-1, acc * n)
  13.  
  14. print(fact(5))
Success #stdin #stdout 0.03s 9620KB
stdin
Standard input is empty
stdout
5 4 3 2 1 0 120