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

def main():

    print """\

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

"""

    #INPUTS
    
    FName = raw_input("Enter the name of the input file containing words: ")
    F = open(FName, "r")
    wordList = F.read().split()
    F.close()
    print 

    #COMPUTATION

    totalLength = 0
    lengthList = [] #Or: lengthList = list()
    for word in wordList: 
        totalLength = totalLength + len(word)
        lengthList.append(len(word))

    '''Alternative method (one of many):
    
    listSize = len(wordList)
    lengthList = range(listSize) #Gets a list of the same size as wordList
    for i in range(listSize):
        totalLength = totalLength + len(wordList[i])
        lengthList[i] = len(wordList[i])
    
    '''
    
    maxLength = max(lengthList)
    minLength = min(lengthList)
    averageLength = float(totalLength) / len(wordList)

    #OUTPUT
    
    print "The longest word length =", maxLength
    print "The shortest word length =", minLength
    print "The average word length =", averageLength
    print ""

main()

'''
Design Question

Using only the tools presented in the lectures, tutorials and labs,
the minimum number of loops required for this program is one.
Both the total length and length list require a loop to compute, and
both can be combined into a single loop.

Using some more advanced knowledge of python functions,
we can actually complete this program without using a loop.
The code would look like the following:

wordList = inputFile.read().split()
combinedList = ''.join(wordList) #Or: string.join(wordList, '')
totalLength = len(combinedList)

maxLength = max(wordList, key=len)
minLength = min(wordList, key=len)
averageLength = float(totalLength) / len(wordList)

See the python documentation for more information on
using max(), min(), and join().

Testing Report

REPORT

Test: 1
File Content: W
*******************W********************
apple
pear
mango
orange
pineapple
lime
lemon

Expected Output: [9,3,5.43]
Actual Output: [9,3,5.42857142857]
Result:Pass

'''