I'm currently working through the MIT Problem Set 2 and I encountered an error that I've fixed, but don't understand why it occurred. The relevant portion of this code is the variable alphabet. I reference it in both functions `is_word_guessed` and `get_guessed_word`. However, when I ran the code, I received the Local variable referenced before assignment error within the `get_guessed_word` function. However, I assigned the variable outside of both functions. On top of that, the function `is_word_guessed` does not produce any errors.

I'm able to fix the error by assigning the alphabet within the function itself, but I'd like to understand the cause of the error so I can learn.

1. Both functions reference the variable alphabet (assigned outside the function), but the only `get_guessed_word` tries to modify the value.
2. I can assume that the error stems from the modification of the variable. But then why doesn't this error appear when I modify secret\_word within the same code? (Is it because secret\_word is an assigned parameter?)

```
secret_word = 'apple'
letters_guessed = ['a','p','q']#['e', 'i', 'k', 'p', 'r', 's']
alphabet='abcdefghijklmnopqrstuvwxyz'

def is_word_guessed(secret_word, letters_guessed):
    '''
    secret_word: string, the word the user is guessing; assumes all letters are
      lowercase
    letters_guessed: list (of letters), which letters have been guessed so far;
      assumes that all letters are lowercase
    returns: boolean, True if all the letters of secret_word are in letters_guessed;
      False otherwise
    '''
    secret_letters=set()
    for l in secret_word:
        if l in alphabet:
            secret_letters.add(l)
            print('Secret letters are ',secret_letters)
        else:
            pass
    for l in letters_guessed:
        if l in secret_letters:
            secret_letters.remove(l)
            print('Secret letters minus guessed letters are', secret_letters)
        else:
            pass
    if len(secret_letters)==0:
        return True
    else:
        return False

print(is_word_guessed(secret_word, letters_guessed))

def get_guessed_word(secret_word, letters_guessed):
    '''
    secret_word: string, the word the user is guessing
    letters_guessed: list (of letters), which letters have been guessed so far
    returns: string, comprised of letters, underscores (_), and spaces that represents
      which letters in secret_word have been guessed so far.
    '''
    ###alphabet='abcdefghijklmnopqrstuvwxyz'
    for l in letters_guessed:
        if l in alphabet:
            alphabet=alphabet.replace(l,'')
            print(alphabet)
    for l in alphabet:
        if l in secret_word:
            secret_word=secret_word.replace(l,'_ ')
            print(secret_word)
    return secret_word

print(get_guessed_word(secret_word, letters_guessed))

```

Thank you in advance for your help. I know this is a common error, but none of the articles I read addressed my specific issue.