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