from evalWord import *
from random import randint

inputFile = 'data.txt'
data = []
outputFile = 'output.txt'
newWords = []
output = []



def getData():
    with open(inputFile,'r') as f:
        data = f.readlines()
    return data

def getError(word):
    return round(evaluateLine(word)[2], 2)

def generateWord(entry):
    outputWord = ''
    entry = entry.split(',')
    srcWords = entry[2:7]
    print(entry[1] + " : " + str(srcWords))
    # track letters left in each source word
    letters = [0,0,0,0,0]
    for i in range(5):
        letters[i] = len(srcWords[i])-1
    # track current focus
    lang = 0 # 0=c, 1=s, 2=h, 3=a, 4=r
    # randomly get letters from source words
    while (all(letters[i] > 0 for i in range(len(letters)))):
        letterToAdd = srcWords[lang][len(srcWords[lang])-letters[lang]-1]
        outputWord += letterToAdd
        letters[lang] -= 1
        lang = randint(0,4)
    return outputWord



data = getData()

for i in range(len(data)):
    newWord = generateWord(data[i])
    newWords.append(newWord)
    output.append(newWord + ',' + data[i].split(',',1)[1][:-1])

print(output)

for i in range(len(newWords)):
    print(str(getError(output[i])))

@@ -696,10 +696,10 @@
 e (a
-ll
+ny
 (let
@@ -754,74 +754,205 @@
     
-letterToAdd = srcWords%5Blang%5D%5Blen(srcWords%5Blang%5D)-letters%5Blang%5D-1%5D%0A
+index = len(srcWords%5Blang%5D)-letters%5Blang%5D-1%0A        if index %3E= 0 and index %3C len(srcWords%5Blang%5D): # if index within range of source word length%0A            letterToAdd = srcWords%5Blang%5D%5Bindex%5D%0A    
     
@@ -981,16 +981,20 @@
 erToAdd%0A
+    
         

edit while condition and check if index in range