input: Write a function to find the maximum number in a list. The function should iterate through the list and compare each element to find the largest one. If the list is empty, the function should return None.
  assert max_num([9, 2, 5, 6, 4, 1])==9
  assert max_num([7, 3, 8, 4, 2, 6])==8
  assert max_num([1, 1, 1, 1, 1])==1
  assert max_num([-4, -2, -7, -9, -1])==-1
  assert max_num([])==None
output: def max_num(lst):
      if not lst:
          return None
      max_val = lst[0]
      for num in lst:
          if num > max_val:
              max_val = num
      return max_val