-4

I've got this task for my python class that I am supposed to do, however I can't seem to print the end result. The aim of the task is to create a program that allows one to encrypt or decrypt using a offset of the users choice, it should then take that information and move the letters of that word by that offset, giving you the encrypted or decrypted product, however the problem is that it won't print, and I can't see whats wrong with it.

Here is my code:

Choice = input("Would you like to decrypt or encrypt a message? Please enter 'E' or 'D': ")
Message = input("Enter text to Cipher: ")
Offset = int(input("Please enter your offset: "))
Encrypt = ''
Decrypt = ''

if Choice == "e".upper:
    for character in Message:
        x = ord(character)
        Encrypt += chr(Offset + x)
    print (Encrypt)
if Choice == "d".upper:
    for character in Message:
        x = ord(character)
        Decrypt += chr(Offset - x)
    print (Decrypt)
Brad Larson
  • 170,088
  • 45
  • 397
  • 571
  • 1
    `"e".upper` is an uninvoked string method. `Choice` isn't ever an univoked string method, so neither of your `if` blocks execute. I *think* you meant `if Choice.upper() == "E"`... Note the parenthesis for method invocation. `"e".upper()` is just a pointlessly silly way to write "E" – John Coleman Nov 05 '15 at 16:48
  • Get rid of all the input code. Hard code some values, e.g. `choice = 'E'` – Peter Wood Nov 05 '15 at 16:48
  • 3
    Follow [PEP8](https://www.python.org/dev/peps/pep-0008/). Use lowercase variable names, e.g. `choice` instead of `Choice`. – Peter Wood Nov 05 '15 at 16:51
  • 1
    Why not compare `choice == 'E'` instead of `'e'.upper()`? – Peter Wood Nov 05 '15 at 16:51

2 Answers2

2

"e".upper is a method. You want "e".upper(). Same for decrypting, of course.

BlivetWidget
  • 10,543
  • 1
  • 14
  • 23
1

upper is a function, not an attribute. Change upper to upper()

anOKsquirrel
  • 140
  • 1
  • 4