input: def exponential_series(x: float, n: int) -> float:
      """Calculate the sum of the first n terms of the exponential series for a given x.
      >>> exponential_series(2, 3)
      15.0
      >>> exponential_series(1, 5)
      6.0
      """
output:     result = 0.0
      factorial = 1
      for i in range(n):
          if i > 0:
              factorial *= i
          result += x ** i / factorial
      return result