PYTHON   32

sum higher

Guest on 5th August 2022 03:02:26 PM

  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3.  
  4.  
  5. def sum_function(max, arg, sum_fn):
  6.     result = 0
  7.     for i in xrange(1, max):
  8.         result += sum_fn(i, arg)
  9.     return result
  10.  
  11. # Test code
  12.  
  13. print sum_function(12, 6, pow)
  14. print sum_function(12, 6, lambda x,y: x+y)
  15. div_float = lambda x,y: x / float(y)
  16. print sum_function(12, 6, div_float)

Raw Paste


Login or Register to edit or fork this paste. It's free.