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