mercredi 21 juin 2017

Else statement syntax error -Python

I am making a Caesar cipher encryption / decryption program in Python 3, and I have an else statement throwing a syntax error. I have looked for similar problems on stack overflow, and found these questions:

else: statement syntax error, simple Python

Python. Noob. Syntax error

Else Syntax Error Python

But I don't have more than one else statement, or a defining clause on my else statement. I don't know what is throwing the error.

My code is:

for symbol in message:
    if symbol in LETTERS:
        num = LETTERS.find(symbol)
        if mode == 'encrypt':
            num += key
        elif mode == 'decrypt':
            num -= key


        if num >= len(LETTERS):
            num -= len(LETTERS)
        elif num < 0:
            num += len(LETTERS)
    translated += LETTERS[num]

    else:
        translated = translated + symbol
print(translated)



     /\

The error is thrown by this else here.

Aucun commentaire:

Enregistrer un commentaire