'''
Created on September 20, 2017
@author: YOUR NAME HERE
'''

def wordToPiglatin(word):
    '''
    returns a piglatin-ized word 
    of string parameter word
    '''
    return word
    
def lineToPiglatin(phrase):
    '''
    returns a piglatin-ized string
    of string parameter phrase
    '''
    # call pigifyword for each word in phrase
    return phrase

def readFile(fname):
    '''
    returns a list of words read from file
    specified by fname
    DO NOT MODIFY THIS FUNCTION
    '''
    f = open(fname)
    st = f.read()
    f.close()
    return st.split()

def writeFile(words, fname):
    '''
    YOU DO NOT NEED TO MODIFY THIS FUNCTION
    write every element in words, a list of strings
    to the file whose name is fname
    put a space between every word written, and make
    lines have length 80
    '''
    LINE_SIZE = 80
    f = open(fname,"w")
    wcount = 0
    for word in words:
        f.write(word)
        wcount += len(word)
        if wcount + 1 > LINE_SIZE:
            f.write('\n')
            wcount = 0
        else:
            f.write(' ')
    f.close()
    
if __name__ == '__main__':
    # start with reading in data file
    filename = "romeo.txt"
    # wordlist is a list of words from the file
    wordlist = readFile(filename)
    print "read",len(wordlist),"words from file",filename 
    
    # result is the file as one long string
    result = ' '.join(wordlist)
    
    # convert to piglatin and write to file
    pigstr = lineToPiglatin(result)
    filenamepig = "pig-" + filename
    writeFile(pigstr.split(),filenamepig)
    print "PIGIFIED " + filename + " as "+ filenamepig
    print "Here are the first 100 characters"
    print pigstr[0:100]  # just print first 100 chars

    # ****** replace comments with code ******
    # read in piglatin file and convert back to a file of English words
    # use output to describe what you are doing as was done above. 
    # ADD CODE HERE

