'''
Created on September 21, 2016
@author: YOUR NAME HERE
'''

def pigifyword(word):
    '''
    returns a piglatin-ized word 
    of string parameter word
    '''
    return word
    
def pigifyall(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
    '''
    f = open(fname)
    st = f.read()
    f.close()
    return st.split()

def writeFile(words, fname):
    '''
    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 = pigifyall(result)
    writeFile(pigstr.split(),"pig-"+filename)
    print "PIGIFIED " + filename + " as pig-"+filename
    print "Here are the first 100 characters"
    print pigstr[0:100]  # just print first 100 chars

    # ****** replace comments with code ******
    # read in pigified file
    # ADD CODE HERE
    # unpigify pigified file that was read
    # ADD CODE HERE
    # write to file "unpig-"+filename
    # ADD CODE HERE
    # print "UNPIGIFIED pig-" + filename + " as unpig-"+filename
    # ADD CODE HERE

