2015-11-05 132 views
-4

我有我的python类,我应该这样做的任务,但我似乎无法打印最终结果。该任务的目的是创建一个程序,允许用户使用偏移量对用户选择进行加密或解密,然后应该获取该信息并将该字母的字母移动该偏移量,从而为您提供加密或解密的产品,但问题是它不会打印,我看不出它有什么问题。凯撒密码,Python

这里是我的代码:

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) 
+1

'“e”.upper'是一个非引用的字符串方法。 'Choice'从来就不是一个一元化的字符串方法,所以你的'if'块都不会执行。我*认为*你的意思是如果Choice.upper()==“E”'...注意方法调用的括号。 ''e“.upper()'只是一个毫无意义的写”E“的方法 –

+0

摆脱所有的输入代码。硬编码一些值,例如'choice ='E'' –

+3

关注[PEP8](https://www.python.org/dev/peps/pep-0008/)。使用小写变量名称,例如'choice'而不是'Choice'。 –

回答

2

"e".upper是一种方法。你想要"e".upper()。当然,解密也是一样。

1

upper是一个函数,而不是一个属性。将upper更改为upper()

+0

而且我通过评论得到了ninja'd ...循环继续... = P – BlivetWidget

+0

@BlivetWidget:P – anOKsquirrel