0
    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.

Brock
  • 5
  • 2
  • 1
    unencryptionKey is indented, is it part of some other function? if so it's not accessible so undefined – Carlo 1585 Feb 21 '19 at 12:41
  • ` unencryptionKey = (-16)` what is this white space? is there a part of code you arent showing us? because it seems like you defined `unencryptionKey ` in another scope so its gone in your loop – Nullman Feb 21 '19 at 12:41
  • Possible duplicate: [short-description-of-the-scoping-rules](https://stackoverflow.com/questions/291978/short-description-of-the-scoping-rules) – Patrick Artner Feb 21 '19 at 12:43
  • The program is fairly long so I did not include all of it. The problem now is that the previous issue is solved but when selecting other options in the program I have some new problems. It looked to me like everything was properly defined but I am new to this. I'm not sure the best way to provide all code without having a huge post. – Brock Feb 23 '19 at 15:57

1 Answers1

0

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

Mansur Fattakhov
  • 387
  • 2
  • 10
  • I appreciate it. That fixed the line in question. The same term comes up with later in the code with the same error so I am guess it is a similar issue. Is that error typically associated with improper spacing/tabs? – Brock Feb 22 '19 at 11:50
  • Python is sensitive to spaces and tabs This is how you define the code block, seems like {} in c++ or js Is that error typically associated with improper spacing/tabs? - it depends, probably you should learn how variable scopes work in Python https://www.python-course.eu/python3_global_vs_local_variables.php – Mansur Fattakhov Feb 22 '19 at 13:45