input: from typing import List, Union
  
  def closest_num(arr: List[Union[int, float]], num: Union[int, float]) -> Union[int, float]:
      """ Find the closest value to the given number in a given array.
      >>> closest_num([5, 4, 8, 7], 5)
      5
      >>> closest_num([3.2, 7.8, 1.5, 6.7], 4.1)
      3.2
      """
output:     closest = arr[0]
      for n in arr:
          if abs(n - num) < abs(closest - num):
              closest = n
      return closest