input: Write a function that takes in two strings and returns an integer indicating the number of common substrings between the two strings. The function should iterate through each possible substring of the first string and check if it exists in the second string. If a common substring is found, the count should be incremented. Finally, the function should return the total count of common substrings. 
  
  def num_common_substrings(s1, s2):
      count = 0
      for i in range(len(s1)):
          for j in range(i + 1, len(s1) + 1):
              if s1[i:j] in s2:
                  count += 1
      return count
  
  assert num_common_substrings("abcd", "bae")==1
  assert num_common_substrings("a", "a")==1
  assert num_common_substrings("abc", "def")==0
  assert num_common_substrings("", "xyz")==0
  assert num_common_substrings("aaa", "aa")==3
output: 
  def num_common_substrings(s1, s2):
      count = 0
      for i in range(len(s1)):
          for j in range(i + 1, len(s1) + 1):
              if s1[i:j] in s2:
                  count += 1
      return count
  