In [1]:
import math
In [2]:
print(math.factorial(5))
In [3]:
print(math.factorial(0))
In [5]:
# print(math.factorial(1.5))
# ValueError: factorial() only accepts integral values
In [4]:
# print(math.factorial(-1))
# ValueError: factorial() not defined for negative values
In [6]:
def permutations_count(n, r):
return math.factorial(n) // math.factorial(n - r)
In [8]:
print(permutations_count(4, 2))
In [7]:
print(permutations_count(4, 4))
In [9]:
def combinations_count(n, r):
return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
In [10]:
print(combinations_count(4, 2))
In [11]:
def combinations_with_replacement_count(n, r):
return combinations_count(n + r - 1, r)
In [12]:
print(combinations_with_replacement_count(4, 2))