UnboundLocalError: local variable 'location' referenced before assignment
<p>I try to write the code for converting words to PigLatin but but it has this error and I cannot sold it. Please show me how to solve this problem.</p>

<pre><code>##The first function is translating words to PIG LATIN

def pigLatinTranslatorForWords(word):
    acc=""
    for ch in word:
        if ch not in 'aeiouyAEIOUY':
            acc+=ch
        else:
            break
    prefix=acc
    first=word[0]
    if word in word.upper():
        if first in 'AEIOU':
            if len(word)==1:
                newWord=first+'way'
            else:
                newWord=word+'WAY'
        else:
            numberOfLeadingConsonants=len(prefix)
            stem=word[numberOfLeadingConsonants:]
            newWord=stem+prefix+"AY"
        print(newWord,end="")
    else:
       if first in 'aeiouAEIOU':
           newWord=word+"way"
           print(newWord,end="")
       else:
           if chr(65)&lt;=first&lt;=chr(90+1):
               firstPart=prefix.lower()
               numberOfLeadingConsonants=len(prefix)
               afterPrefix=word[numberOfLeadingConsonants:]
               newFirstletter=afterPrefix[0]
               capitalizeFirstLetter=newFirstLetter.capitalize()
               stem=capitalizeFirstLetter+afterPrefix[1:]
               if word[1:]in word.lower():
                   newWord=stem+firstPart+"ay"
                   print(newWord, end="")
               else:
                   newWord=stem+prefix+"ay"


                 print(newWord,end="")
               elif chr(97)&lt;=first&lt;=chr(122+1):
                   numberOfLeadingConsonants=len(prefix)
                   afterPrefix=word[numberOfLeadingConsonants:]
                   newFirstLetter=afterPrefix[0]
                   decapitalizeFirstLetter=newFirstletter.lower()
                   stem=decapitalizeFirstLetter+afterPrefix[1:]
                   newWord=stem+prefix+"ay"
                   print(newWord,end="")

    ## The second function is translating both pieces of he hyphenated word while preserving the hyphen

    def breakup(word):
        text=word.split("-")
        "-".join(text)
        for word in text:
            pigLatinTranslatorForWords(word)

    ##The third function is preserving punctuation in the position relative to word

    def correcPunctuation(word):
        letters=""
        punctuation=""
        for ch in word:
            if ch not in '."()!?':
                letters+=ch
            else:
                location=word.find(ch)
                punctuation+=ch
        if location!=0:
            translatedWord=pigLatinTranslatorForWords(letters)
            print(punctuation, end="")
        else:
            print(punctuation,end="")
            translatedWord=pigLatinTranslatorForWords(letters)

    ## The fourth function is translating sentences to PIG LATIN

    def translateSentenceIntoPigLatin():
        sentence=input("Please give me one senctence in order to translate to Pig Latin.")
        text=sentence.split()
        for word in text:
            if word.find("-")!=(-1):
                breakup(word)
                print("",end="")
            elif word.find(".")!=(-1)or word.find("(")!=(-1)or word.find(")")!=(-1)or word.find("!")!=(-1)or word.find("?")!=(-1) or word.find("")!=(-1):
                correcPunctuation(word)
                print("",end="")
            else:
                pigLatinTranslatorForWords(word)
                print("",end="")
</code></pre>
