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