# Ryan Martin
# macid: abcd123
# student number: #######
# July 12, 2011
#
# This is a solution for Marked Assignment 2 (Lab 05) on Monday.

def main():

    print """\

This program is a solution to Marked Assignment 2 (Lab 05) on Monday.

"""

    #INPUTS
    
    FList = raw_input("Enter the name of three files containing words, separated by spaces: ")
    FList = FList.split()

    searchWord = raw_input("Enter the word to search for in each file: ")
    print
   
    #COMPUTATION
   
    inputFile1 = open(FList[0], "r")
    wordList1 = inputFile1.read().split()
    inputFile1.close()
    inputFile2 = open(FList[1], "r")
    wordList2 = inputFile2.read().split()
    inputFile2.close()
    inputFile3 = open(FList[2], "r")
    wordList3 = inputFile3.read().split()
    inputFile3.close()
    
    file1Results = wordList1.count(searchWord)
    file2Results = wordList2.count(searchWord)
    file3Results = wordList3.count(searchWord)

    '''Alternative method (one of many):
    
    wordLists = []
    for inputFileName in FList:
        inputFile = open(inputFileName, "r")
        wordList.append(inputFile.read().split())
        inputFile.close()
    
    file1Results = wordLists[0].count(searchWord)
    file2Results = wordLists[1].count(searchWord)
    file3Results = wordLists[2].count(searchWord)

    '''

    #OUTPUT
    
    print "Matches in", FList[0], "=", file1Results
    print "Matches in", FList[1], "=", file2Results
    print "Matches in", FList[2], "=", file3Results
    print ""

main()

'''
Design Question

Adapting this program to handle an unknown number of files
is just a matter of storing results in a list instead.
Using a loop to iterate through each given filename,
a variable number of files can then be processed:

results = []
for inputFileName in FList:
    inputFile = open(inputFileName, "r")
    wordList = inputFile.read().split()
    inputFile.close()
    matches = wordList.count(searchWord)
    results.append(matches)
    print "Matches in", inputFileName, "=", matches

Testing Report

REPORT

Test: 1
Input: [sample1.txt, sample2.txt, sample3.txt], searchWord: apple
***************file1List*****************
apple
apple
pear
mango
orange
apple
***************file2List*****************
apple
banana
apple
apple
orange
apple
***************file3List*****************
apple
banana
apple
orange
orange
orange

Expected Output: [3,4,2]
Actual Output: [3,4,2]
Result:Pass