fork download
  1. def nth_elm(n):
  2. return ((-1)**(n+1))/n
  3.  
  4. def nth_elm_func_2(n):
  5. return (1/n)
  6.  
  7. def sum_of_pogression(func, n):
  8. return sum(map(func, range(1, n+1)))
  9.  
  10. print(sum_of_pogression(nth_elm, 3))
  11. print(sum_of_pogression(nth_elm_func_2, 3))
Success #stdin #stdout 0.04s 9312KB
stdin
Standard input is empty
stdout
0.8333333333333333
1.8333333333333333