The math.perm()
function computes the number of ways to choose k items from n items with order and without repetition.
math.perm(n, k = None)
The optional parameter k, if not specified, defaults to n.
The function returns the value of n! / (n - k)! when k <= n . If k > n, the function returns zero.
import math
print(math.perm(3))
print(math.perm(5))
print(math.perm(10, 3))
print(math.perm(14, 7))
print(math.perm(100, 10))
The function raises TypeError
if either of the arguments are not integers. A ValueError
if either of the arguments are negative.
import math
math.perm('5', 5)
import math
math.perm(-10, 2)