2017-06-17 4 views
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="" 
    for l in plaintext(): 
     if l in dic: 
      l=dic[l] 
     ciphertext+=l 

    return ciphertext 



print [caesar(plaintext)] 

なぜ私にエラーが出るのか分かりません。私は援助が必要です。私は括弧を入れて、パラセシスを置き換えようとしましたが、それでもそのエラーが出ています。エラーが発生しましたこのシーザー暗号でリストオブジェクトを呼び出すことができません

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

まず最初に、 'print(caesar(plaintext))'はPython 3.xでの印刷方法です。 – ifconfig

+0

それでも同じエラーを出すことは変わりません –

+0

あなたの質問に完全なエラートレースバックを追加してください。 plaintext()のlの –

答えて

0
  1. まず、print(caesar(plaintext))は、Python 3.xで印刷する方法であります
  2. また、それにlen()を呼び出さずにリストを反復することはできません:あなたは、文字列をインクリメントすることはできませんfor l in range(len(plaintext)):
  3. ので、私はあなたが本当に変数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)) 

EDIT

あなたはシーザー暗号を作りたい場合は、this web siteはPythonでそれを作る方法を説明するの偉大な仕事をしていません。

+0

私の平文を暗号文に変更する必要があります。変更によって出力がintを返すようにしました –

+0

正しいですが、あなたのコードはそれをとにかく行いません。私はあなたが出力文字列に文字を追加しようとするところはどこにも見えません。 – ifconfig

関連する問題