MCPcopy Create free account
hub / github.com/geekcomputers/Python / factorial

Function factorial

primelib/primelib.py:596–610  ·  view source on GitHub ↗

input: positive integer 'n' returns the factorial of 'n' (n!)

(n)

Source from the content-addressed store, hash-verified

594
595
596def factorial(n):
597 """
598 input: positive integer 'n'
599 returns the factorial of 'n' (n!)
600 """
601
602 # precondition
603 assert isinstance(n, int) and (n >= 0), "'n' must been a int and >= 0"
604
605 ans = 1 # this will be return.
606
607 for factor in range(1, n + 1):
608 ans *= factor
609
610 return ans
611
612
613# -------------------------------------------------------------------

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected