input: Write a function to find the total number of common characters present in both strings. The function should take two string inputs and return an integer representing the number of common characters.
  
  def num_common_chars(str1, str2):
      common = 0
      for c in str1:
          if c in str2:
              common += 1
      return common
  
  assert num_common_chars("hello", "world") == 3
  assert num_common_chars("python", "java") == 1
  assert num_common_chars("abc", "def") == 0
  assert num_common_chars("programming", "gaming") == 4
  assert num_common_chars("", "code") == 0
output: def num_common_chars(str1, str2):
      common = 0
      for c in str1:
          if c in str2:
              common += 1
      return common