简体   繁体   中英

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. In the first line it shows exactly what 'unencryptionKey' is. 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. 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. remove the spaces before unencryptionKey , it should be on the same level as def passwordunEncrypt

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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