plaintext =[
"this is a test",
"caesar’s wife must be above suspicion",
"as shatner would say: you, should, also, be, able, to, handle, punctuation.",
"to mimic chris walken: 3, 2, 1, why must you, pause, in strange places?",]
shift = 3
def caesar(plaintext):
alphabet=["a","b","c","d","e","f","g","h","i","j","k","l",
"m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
dic={}
for i in range(0,len
(alphabet)):
dic[alphabet[i]]=alphabet[(i+shift)%len(alphabet)]
ciphertext=""
for l in plaintext():
if l in dic:
l=dic[l]
ciphertext+=l
return ciphertext
print [caesar(plaintext)]
我不确定为什么它会给我这个错误。我需要一些帮助。我尝试将括号括起来并替换了parathesis,但它仍然给出了错误。
Traceback (most recent call last):
File "C:/Users/iii/Desktop/y.py", line 33, in <module>
print (caesar(plaintext))
File "C:/Users/iii/Desktop/y.py", line 24, in caesar
for l in plaintext():
TypeError: 'list' object is not callable
答案 0 :(得分:0)
print(caesar(plaintext))
是如何在Python 3.x中打印。len()
的情况下遍历列表:for l in range(len(plaintext)):
ciphertext
添加1,请将其设为数字:ciphertext=0
这个修改过的代码运行没有错误,只要它仍然是你想要的,我无法确定它是否。
plaintext =[
"this is a test",
"caesar’s wife must be above suspicion",
"as shatner would say: you, should, also, be, able, to, handle, punctuation.",
"to mimic chris walken: 3, 2, 1, why must you, pause, in strange places?",]
shift = 3
def caesar(plaintext):
alphabet=["a","b","c","d","e","f","g","h","i","j","k","l",
"m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
dic={}
for i in range(0,len(alphabet)):
dic[alphabet[i]]=alphabet[(i+shift)%len(alphabet)]
ciphertext=0
for l in range(len(plaintext)):
if l in dic:
l=dic[l]
ciphertext+=l
return ciphertext
print(caesar(plaintext))
<强> 修改 强>
如果你想制作一个Caesar密码,this web site可以很好地解释如何用Python编写它。