# wget http://cs.whitman.edu/~davisj/cs/167/2016F/exmpls/sentencecount.py

def wordCount5(text):
  """
  Count the number of words in a string. (Havill 2016, p. 247)
  Parameter:
    text: a string object
  Return value: the number of words in text
  """
  count = 0
  prevCharacter = ' '
  for character in text:
    if character in ' \t\n' and prevCharacter not in ' \t\n':
      count += 1
    prevCharacter = character
  if prevCharacter not in ' \t\n':
    count += 1
  return count

def sentenceCount(text):
  """
  Count the number of sentences in a string. (Havill 2016, exercise 6.1.9)
  Sentences are delimited by periods, question marks, and exclamation points.
  Parameter: 
    text: a string object
  Return value: the number of sentences in text
  """
  pass

def wordCountFile(filename):
  """
  Return the number of words in the file with the given name.
  Parameter:
    filename: The name of a text file
  Return value: The number of words in the file
  """
  textfile = open(filename, 'r', encoding='utf-8')
  text = textfile.read()
  textfile.close()
  return wordCount5(text)

def sentenceCountFile(filename):
  """
  Return the number of sentences in the file with the given name.
  Sentences are delimited by periods, question marks, and exclamation points.
  Parameter: 
    filename: The name of a text file
  Return value: The number of sentences in the file
  """
  pass

def testCounters():
  exclamations = "Wait! How did you do that?\nWow...  That is amazing!!!"
  print()
  print(exclamations)
  print("Words:", wordCount5(exclamations))
  print("Sentences:", sentenceCount(exclamations))
  print()
  print("Word count in 'A Tale of Two Cities':",
        wordCountFile('ataleoftwocities.txt'))
  print("Sentence count in 'A Tale of Two Cities':",
        sentenceCountFile('ataleoftwocities.txt'))

if __name__=='__main__':
  testCounters()
