# ACT2-2 functions.

# Lines that start with '#' are COMMENTS.
# They are not interpreted by Python.

# Triple quotes in the first line describe the program.
# They are not interpreted by Python either.

def avg3(someList):
    '''Takes a list of three numbers and returns the average'''
    s = someList[0] + someList[1] + someList[2]
    avg = s/3.0
    return avg

def addOne(t):
    '''Takes a number and returns that number plus one'''
    y = t + 1
    return y

# This line assigns a string to a variable named stringToSplit.
stringToSplit ='Sarah Cynthia Sylvia Stout\nWould not take the garbage out!\nShe\'d scour the pots and scrape the pans,\nCandy the yams and spice the hams,\nAnd though her daddy would scream and shout,\nShe simply would not take the garbage out.'

# Remove the '#' characters as you write the functions below.

def readShel():
    '''Read in poem.txt and returns a list of words'''
    fileName = "poem.txt"
    myFile = open(fileName,"r")
    fileString = myFile.read()
    myFile.close()
    myList = fileString.split()
    return myList

def countWordsInShel():
    '''Returns the number of words in poem.txt'''
    myList = readShel()
    count = 0
    for word in myList:
        count = count + 1
    return count

def readMobyDick():
    '''Reads the text file MobyDick.txt and returns a list of words'''
    fileName = "MobyDick.txt"
    myFile = open(fileName,"r")
    fileString = myFile.read()
    myFile.close()
    myList = fileString.split()
    return myList

def countWordsInMobyDick():
    '''Counts the number of words in MobyDick.txt'''
    myList = readMobyDick()
    count = 0
    for word in myList:
        count = count + 1
    return count 

def avgWordLengthInMobyDick():
    '''Gets the average word length in MobyDick.txt'''
    myList = readMobyDick()
    s = 0
    for word in myList:
        s = s + len(word)
    avg = s/float(len(myList))
    return avg

def getLongestWordInMobyDick():
    '''Returns the longest word in MobyDick.txt'''
    myList = readMobyDick()
    longestlen = 0
    longestword = ""
    for word in myList:
        if len(word) > longestlen:
            longestlen = len(word)
            longestword = word
    return longestword
