# woc2.py
# Written by Todd Wareham for CS 2500
"""
Given the name of a text file and a word as command-line arguments, prints 
 the number of exact (case-sensitive) and inexact (case-insensitive) 
 occurences of that word in the file, as well as the number of other words
 and the total number of words.
"""

import sys

if len(sys.argv) != 3:
    print "usage: python", sys.argv[0], "filename word"
    sys.exit(1)

WEcount = WIcount = WOcount = Wcount = 0

for line in open(sys.argv[1]):
    for x in line.split():
        if x == sys.argv[2]:
	    WEcount = WEcount + 1
        elif x.lower() == (sys.argv[2]).lower():
	    WIcount = WIcount + 1
        else:
	    WOcount = WOcount + 1
        Wcount = Wcount + 1

print "The word \"", sys.argv[2], "\" occurs", WEcount, \
      "times exactly and", WIcount, "times inexactly in file ", sys.argv[1]
print " (", WOcount, "other words and", Wcount, "words in total)"

