[ create a new paste ] login | about

Link: http://codepad.org/y2uvcMPc    [ raw code | fork ]

kamarakay2000 - Python, pasted on Jun 4:
import fileinput
def fileCheck(fileName):
    try:
        fileObj = open(fileName)
        return 0
    except IOError:
        print("could not locate file" +fileName)
        return 1
    def dictionaryList(fileName):
        allAbbreviations = []
        allTranslations =[]
        fileObj = open(fileName)
        for line in iter(fileObj):
            allAbbreviations.append(wordInLine[0])
            translation =""
            totalNumberOfWords = len(wordsInTheLine)

            for x in range(2,totalNumbeOfWords):
                translation = translation +wordsInLine[x]+""
                return(allAbbreviations,allTranslations)
            def compare(messageWords,allAbbreviations,alltranslations):
                finalMessage = ""
                for wordPosition in range(0,len(messageWords)):
                    currentWord = messageWords[wordPosition]
                    try:
                        matchPosition = allAbbreviation.index(currentWord.upper)
                        finalMessage = finalMessage + ""+allTranslations[matchPositin]
                    except:
                        finalMessage = finalMessage +""+currentWord
                        return(finalMessage)
def mainFunction():
                        print("please enter the message(no punctuation please)")
                        textMessage = input(">")
                        messageWords = textMessage.split()
                        translationFileName = "Translation.txt"
                        fileFound = fileCheck(translationFileName)
                        if fileFound == 0:
                            allAbbreviations,alltranslations = dictionaryList(translationFileName)
                            translatedMessage = compare(messageWords,allAbbreviations,allTranslations)
                            print(translatedMessage)
                        else:
                            print("could not translate message, file containing translation terms could not be located")



 


Output:
No errors or program output.


Create a new paste based on this one


Comments: