fork download
  1. def fact(n):
  2. '''
  3. Calculate 1*2*...*n
  4.  
  5. >>> fact(1)
  6. 1
  7. >>> fact(10)
  8. 3628800
  9. >>> fact(-1)
  10. Tracbackv (most recent call last)
  11. ···
  12. ValueError
  13. '''
  14. if n < 1:
  15. raise ValueError()
  16. if n == 1:
  17. return 1
  18. return n * fact(n - 1)
  19.  
  20. if __name__ == '__main__':
  21. import doctest
  22. doctest.testmod()
  23.  
  24. # your code goes here
Success #stdin #stdout 0.44s 21412KB
stdin
Standard input is empty
stdout
Standard output is empty