Python - 嵌套迭代的语法错误?

时间:2014-05-29 20:13:35

标签: python for-loop syntax nested syntax-error

所以我有这段代码:

Chars = maketrans(" ABCDEFGHIJKLMNOPQRSTUVWXYZ-.,"," ABCDEFGHIJKLMNOPQRSTUVWXYZ-.,");

input = input.split(" ");
length = len(input);
charLength = len(Chars);
    for x in range(1,length):
            for y in range(1,charLength):
                for z in range(MinInt,MaxInt):
                    if Transform(z + x.translate(Chars) + Key)[:5] == input[x]
                        print x.translate(Chars)

该函数接收由空格分隔的5个字符的块。尝试运行它时,我收到以下错误:

File "SH25.py", line 21
if Transform(z + x.translate(Chars) + Key) == input[x]
                                                         ^
SyntaxError: invalid syntax

我当然是Python的新手,但有人可以帮忙吗?感谢。

1 个答案:

答案 0 :(得分:1)

错误消息非常精确::

后需要if
if Transform(z + x.translate(Chars) + Key)[:5] == input[x]: