input: Write a function to find the closest value to a given number in a given array. The function should take an array and a number as inputs and return the closest value in the array to the given number. If the array is empty, return None.
  assert closest_num([5, 4, 8, 7], 5)==5
  assert closest_num([3, 2, 4, 3, 5], 6)==5
  assert closest_num([1, 2, 3, 4, 5], 3)==3
  assert closest_num([10, 20, 30, 40], 15)==10
  assert closest_num([], 5)==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