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