[Tutor] syntax error help

Alan Gauld alan.gauld at yahoo.co.uk
Fri Aug 26 19:18:02 EDT 2016


On 30/03/16 19:05, Awais Mamoon wrote:
> Hi my code should be working however keeps coming up with invalid syntax but
> I know there isn’t one. 

You are wrong. There is.
I suspect the error message tells you where it is.
In future please include the full error message with your code.

Look closely at this function:

> def EncryptionOrDecryption(plaintext_message, Keyword):
> 
>      NewLetter = ("")
>      Ciphertext = ("")
>      PositionKeyword = 0
>      print('Do you wish to encrypt or decrypt')
>      option = input()
> 
>      if option == "e" or "encrypt":
>           for i in plaintext_message:
>                if i == "":
>                     Ciphertext = Ciphertext + ""
>                else:
>                     NewLetter = (alphabet.index(i)+1) +
> alphabet.index(Keyword[PositionKeyword]
>                     PositionKeyword = PositionKeyword + 1
>                     if PositionKeyword == len(Keyword):
>                          PositionKeyword = 0
>                     if NewLetter > 25:
>                         NewLetter = NewLetter - 26
>                    Ciphertext = Ciphertext + alphabet[NewLetter]
>      return Ciphertext
> 
>      elif option == "d" or "decrypt":
>            for i in plaintext_message:
>                if i == "":
>                     Ciphertext = Ciphertext + ""
>                else:
>                     NewLetter = (alphabet.index(i)-1) +
> alphabet.index(Keyword[PositionKeyword])
>                     PositionKeyword = Keyword + 1
>                     if PositionKeyword == len(Keyword):
>                          PositionKeyword = 0
>                     if NewLetter > 25:
>                          NewLetter = NewLetter - 26
>                Ciphertext = Ciphertext + alphabet[NewLetter]
>      return Ciphertext


-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos




More information about the Tutor mailing list