Start New Discussion within our **Software Development Community** # Number of Permutations (Python)

```
''' permutation_number1.py
find the number of ordered permutations of items
taken from a population of known size
see also:
http://www.mathwords.com/p/permutation_formula.htm
tested with Python27/33 and IronPython273 by vegaseat 27feb2013
'''
from math import factorial
def number_permutations(n, k):
'''
return the number of ordered permutations of
k items taken from a population of size n
uses algorithm n!/(n-k)!
'''
return factorial(n)/factorial(n-k)
q = '''\
How many ways can 4 students from a group of 15
be lined up for a photograph?
'''
print(q)
print(number_permutations(15, 4))
''' result ...
How many ways can 4 students from a group of 15
be lined up for a photograph?
32760
'''
q2 = '''
How many ways can you permutate 'abc'?
'''
print(q2)
print(number_permutations(3, 3))
''' result ...
How many ways can you permutate 'abc'?
6
'''
```

The article starter has earned a lot of community kudos, and such articles offer a bounty for quality replies.