Task
How many different ways are there to use 16 possible variables? Give the Python code.
Verbalization
Calculation formula is 18C0 + 18C1 +18C2 …… + 18C18
nCr = n!/((n-r)!*r!) (use from math import factorial factorial(i) = i!)
Use roop and += (for i in range(18+1))
Code
from math import factorial
#test n=18C0
n= factorial(18)/factorial(18-0)*factorial(0)
n
#test How many different ways are there to use 3 possible adjustment variables?
n =factorial(3)/(factorial(3-0)*factorial(0)) +factorial(3)/(factorial(3-1)*factorial(1)) +factorial(3)/(factorial(3-2)*factorial(2)) +factorial(3)/(factorial(3-3)*factorial(3))
n
h = 16
n = 0
for i in range(0,h+1):
f = factorial(h)/(factorial(h-i)*factorial(i))
n += f
n
Reference