```
''' 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
'''
```

1

Contributor0

Replies17

Views**Are you able to help answer this sponsored question?**

Questions asked by members who have earned a lot of community kudos are featured in order to give back and encourage quality replies.

Recommended Topics