input: Write a function to find the closest value to a given number in a given array. The function should return the closest value if it exists, otherwise it should return None.
  def closest_num(arr, num):
      if not arr:
          return None
      closest = arr[0]
      for value in arr:
          if abs(value - num) < abs(closest - num):
              closest = value
      return closest
  
  assert closest_num([5, 4, 8, 7], 5) == 5
  assert closest_num([3, 5, 10, 1, 2], 9) == 10
  assert closest_num([4, 3, 1, 2], 2.5) == 2
  assert closest_num([3, 5, 4, 1, 2], 8) == 5
  assert closest_num([], 7) == None
output: def closest_num(arr, num):
      if not arr:
          return None
      closest = arr[0]
      for value in arr:
          if abs(value - num) < abs(closest - num):
              closest = value
      return closest