Python TypeError: list indices must be integers or slices, not tuple. Caesar Cypher Decoder
Python TypeError: list indices must be integers or slices, not tuple. Caesar Cypher Decoder
我正在为 Caesar Cyphers 编写解密器,它不需要用户输入消息更改的数量。然后它将查找常见的字母出现并将匹配最多的字母打印到最少的匹配项。它会打印出来。只是没有订单。我的目标是将解码后的消息和出现次数保存到二维数组中。但是我遇到了这个问题。 returns 当我尝试编辑数组时出现此错误。在此先感谢您的帮助。
import sys
import time
from time import sleep as s
import random
import collections
global c1, message, letters, array, i, output
letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
lletters = letters.lower()
length = len(letters)
space = " "
length1 = len(space)
c1 = int(0)
check = ["hi", "ing", "ai", " i ", "oo", "e ", "as", "wh", "er", "th", "re", "or", "eir", " if ", "en", "ph", "zz", "ll", "ff", "ei", "ie", " a ", "qu", "eu", "au", "ue", "ca"]
output = [25,1]
message = input("Enter the thing you want to decrypt. ")
def decrypt():
global c1, letters, message, list1
decrypted = ''
for counter in range(1,26):
decrypted = ""
c1 = int(counter)
p = int(counter - int(1))
for chars in message:
if chars in letters:
num = letters.find(chars)
num -= c1
num = num%length
decrypted += letters[num]
elif chars in lletters:
num = lletters.find(chars)
num -= c1
num = num%length
decrypted += lletters[num]
elif chars in space:
decrypted += space
ho = int(0)
h1 = int(0)
for i in range(len(check)):
h = check[i]
if h in decrypted.lower():
output[p,1] = int(h1)
h1 = h1 + int(1)
output[p,1] = int(h1)
if ho == int(0):
ho = int(1)
print(str(output[p,2]))
print(decrypted)
decrypt()
你的错误在于列表切片语法。它是 l[start:finish] 而不是 l[start, finish]。更改此行:
print(str(output[p,2])
至:
print(str(output[p:2])
我正在为 Caesar Cyphers 编写解密器,它不需要用户输入消息更改的数量。然后它将查找常见的字母出现并将匹配最多的字母打印到最少的匹配项。它会打印出来。只是没有订单。我的目标是将解码后的消息和出现次数保存到二维数组中。但是我遇到了这个问题。 returns 当我尝试编辑数组时出现此错误。在此先感谢您的帮助。
import sys
import time
from time import sleep as s
import random
import collections
global c1, message, letters, array, i, output
letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
lletters = letters.lower()
length = len(letters)
space = " "
length1 = len(space)
c1 = int(0)
check = ["hi", "ing", "ai", " i ", "oo", "e ", "as", "wh", "er", "th", "re", "or", "eir", " if ", "en", "ph", "zz", "ll", "ff", "ei", "ie", " a ", "qu", "eu", "au", "ue", "ca"]
output = [25,1]
message = input("Enter the thing you want to decrypt. ")
def decrypt():
global c1, letters, message, list1
decrypted = ''
for counter in range(1,26):
decrypted = ""
c1 = int(counter)
p = int(counter - int(1))
for chars in message:
if chars in letters:
num = letters.find(chars)
num -= c1
num = num%length
decrypted += letters[num]
elif chars in lletters:
num = lletters.find(chars)
num -= c1
num = num%length
decrypted += lletters[num]
elif chars in space:
decrypted += space
ho = int(0)
h1 = int(0)
for i in range(len(check)):
h = check[i]
if h in decrypted.lower():
output[p,1] = int(h1)
h1 = h1 + int(1)
output[p,1] = int(h1)
if ho == int(0):
ho = int(1)
print(str(output[p,2]))
print(decrypted)
decrypt()
你的错误在于列表切片语法。它是 l[start:finish] 而不是 l[start, finish]。更改此行:
print(str(output[p,2])
至:
print(str(output[p:2])