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