input: Write a function to find the closest value to a given number in a given array. If the given array is empty, return None.
  assert closest_num([5, 4, 8, 7], 5)==5
  assert closest_num([1, 2, 3], 2)==2
  assert closest_num([10, 20, 30], 15)==10
  assert closest_num([], 5)==None
  assert closest_num([1, 3, 7], None)==None
output: def closest_num(arr, target):
      if not arr or target is None:
          return None
      closest = arr[0]
      for num in arr:
          if abs(num - target) < abs(closest - target):
              closest = num
      return closest