为什么我的术语在 python 中显示为未定义?

Why does my term show up as undefined in python?

    unencryptionKey = (-16)


# Caesar Cypher Encryption
def passwordunEncrypt(encryptedMessage, key):

    # We will start with an empty string as our encryptedMessage
    encryptedMessage = ''


# For each symbol in the unencryptedMessage we will add an encrypted symbol into the encryptedMessage
for symbol in 'encryptedMessage':
    if symbol.isalpha():
        num = ord(symbol)
        num += unencryptionKey

当我 运行 上面的代码时,它告诉我,在最后一行中,'unencryptionKey' 是未定义的。在第一行中,它准确地显示了 'unencryptionKey' 是什么。为什么会出错?在原始代码中,最后一行中的术语只是 'key',所以我更改了它,因为我假设它们的意思是要使用 unencryptionKey,并且认为将其绑定到第一行将允许它 运行。我尝试截屏以便包含行号,但它不起作用,所以不得不剪切和粘贴。

似乎 unencryptionKey 不是在全局范围内定义的,而是在某些函数中定义的。去掉unencryptionKey前的空格,应该和def passwordunEncrypt

在同一层