- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- def sum_function(max, arg, sum_fn):
- result = 0
- for i in xrange(1, max):
- result += sum_fn(i, arg)
- return result
- # Test code
- print sum_function(12, 6, pow)
- print sum_function(12, 6, lambda x,y: x+y)
- div_float = lambda x,y: x / float(y)
- print sum_function(12, 6, div_float)