import doctest from typing import Callable # term :: int -> int def cube(x: int) -> int: """ Evaluates cube of given number. >>> cube(3) 27 >>> cube(5) 125 """ return x * x * x # term :: int -> int def summation( n: int, term: Callable[[int], int], ) -> int: """ Sums first n numbers of series. >>> summation(5, cube) 225 >>> summation(5, lambda k: 8 // ((4 * k - 3) * (4 * k - 1))) 2 """ total = 0 for k in range(1, n + 1): total += term(k) return total if __name__ == "__main__": doctest.testmod()