input: Write a function to find the maximum number in a list. If the list is empty, return None. The function should iterate through the list and keep track of the largest number encountered.
  assert max_num([9, 2, 5, 6, 4, 1])==9
  assert max_num([1, 2, 3, 4, 5])==5
  assert max_num([-1, -2, -3, -4, -5])==-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