MCPcopy Create free account
hub / github.com/subbarayudu-j/TheAlgorithms-Python / factorial

Function factorial

other/primelib.py:567–581  ·  view source on GitHub ↗

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

(n)

Source from the content-addressed store, hash-verified

565# -----------------------------------------------------------------
566
567def factorial(n):
568 """
569 input: positive integer 'n'
570 returns the factorial of 'n' (n!)
571 """
572
573 # precondition
574 assert isinstance(n,int) and (n >= 0), "'n' must been a int and >= 0"
575
576 ans = 1 # this will be return.
577
578 for factor in range(1,n+1):
579 ans *= factor
580
581 return ans
582
583# -------------------------------------------------------------------
584

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected