简体   繁体   English

Python 类型错误:列表索引必须是整数或切片,而不是元组。 凯撒 Cypher 解码器

[英]Python TypeError: list indices must be integers or slices, not tuple. Caesar Cypher Decoder

I am working on writing a decrypter for Caesar Cyphers that won't require the user to input the amount the message was changed by.我正在为 Caesar Cyphers 编写一个解密器,它不需要用户输入消息更改的数量。 It will then look for common letter occurrences and print the ones with the most matches down to the lest matches.然后它将查找常见的字母出现,并将匹配最多的字母打印到最少的匹配。 It will print them all fine.它会很好地打印它们。 Just without an order.只是没有订单。 My aim was to save the decoded messages and the amount of occurrences to a 2d array.我的目标是将解码的消息和出现的数量保存到二维数组中。 Yet I have reached a problem with this.然而我遇到了这个问题。 It returns this error when I try to edit the array.当我尝试编辑数组时,它会返回此错误。 Thanks in advance for any help.提前感谢您的帮助。

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()

Your mistake is in the list slicing syntax.您的错误在于列表切片语法。 It is l[start:finish] not l[start, finish].它是 l[start:finish] 而不是 l[start,finish]。 change this line:改变这一行:

print(str(output[p,2])

to:至:

print(str(output[p:2])

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 TypeError:列表索引必须是整数或切片,而不是元组 - TypeError: list indices must be integers or slices, not tuple TypeError:列表索引必须是整数或切片,而不是元组? - TypeError: list indices must be integers or slices, not tuple? Python棋盘游戏-“类型错误:列表索引必须是整数或切片,而不是元组” - Python Board Game - "TypeError: list indices must be integers or slices, not tuple" Python 类型错误:列表索引必须是整数或切片,而不是元组 - Python TypeError: list indices must be integers or slices, not tuple 类型错误:列表索引必须是整数或切片,而不是在 python 中使用 sys 导入的元组 - TypeError: list indices must be integers or slices, not tuple with sys import in python Python:“列表索引必须是整数或切片,而不是元组” - Python:'list indices must be integers or slices, not tuple' Python TypeError:元组索引必须是整数或切片,而不是元组? - Python TypeError: Tuple indices must be integers or slices, not tuple? TypeError:列表索引必须是整数或切片,而不是元组列表的元组 - TypeError: list indices must be integers or slices, not tuple for list of tuples 列表类型错误:列表索引必须是整数或切片,而不是元组 - List of lists TypeError: list indices must be integers or slices, not tuple TypeError:列表索引必须是整数或切片,而不是电影分级数据的元组 - TypeError: list indices must be integers or slices, not tuple for Movie Rating Data
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM