简体   繁体   English

为什么我的字词在python中显示为undefined?

[英]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

When I run the above code it tells me that, in the last line, 'unencryptionKey' is undefined. 当我运行上面的代码时,它告诉我在最后一行中,“ unencryptionKey”是未定义的。 In the first line it shows exactly what 'unencryptionKey' is. 在第一行中,它确切显示了“ unencryptionKey”是什么。 Why the error? 为什么会出错? In the original code the term in the last line was just 'key' so I changed it as I assume they mean unencryptionKey is to be used and thought tying it to the first line would allow it to run. 在原始代码中,最后一行中的术语只是“密钥”,因此我对其进行了更改,因为我认为这意味着将使用unencryptionKey,并认为将其绑定到第一行将允许它运行。 I tried to screenshot so the line numbers would be included but it didn't work so had to cut and paste. 我尝试截屏,以便包含行号,但是行不通,因此必须剪切并粘贴。

it seems like unencryptionKey defined not in global scope but in some function. 似乎unencryptionKey不是在全局范围内定义的,而是在某些函数中定义的。 remove the spaces before unencryptionKey , it should be on the same level as def passwordunEncrypt 删除unencryptionKey之前的空格,它应与def passwordunEncrypt处于同一级别

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM