Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/362.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 语法错误:解析时出现意外的EOF(小代码)_Python - Fatal编程技术网

Python 语法错误:解析时出现意外的EOF(小代码)

Python 语法错误:解析时出现意外的EOF(小代码),python,Python,我的密码。编辑器上不会显示任何错误 def word_to_code(word): #TODO1 myTranslatedWord = "" for a in range(0, len(word)): for b in range(0, len(code)): if(word[a] == code[b]): myTranslatedWord += code[b] print(myTranslatedWord) return(myTranslated

我的密码。编辑器上不会显示任何错误

def word_to_code(word):
#TODO1
myTranslatedWord = ""
for a in range(0, len(word)):
    for b in range(0, len(code)):
        if(word[a] == code[b]):
            myTranslatedWord += code[b]
print(myTranslatedWord)
return(myTranslatedWord)

code = {'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': '===.====.=.='}

print((word_to_code("PAPI"))

这是一门我试图独立解决一个目标的课程。由于某种原因,尽管我的代码不起作用。

最后一行中的括号太多了。应该是

print(word_to_code("PAPI"))
将来,将错误的实际文本复制到问题中,而不是作为图片



请注意,如何进行翻译还有一个相当大的问题。记住字典的好处——您应该能够只使用一个循环编写该函数。

您能修复缩进吗?看起来像缩进问题。非常感谢。错误已修复,但现在弹出了一个新错误。我是新来的,我已经去TutorialPoint找字典了,但是我想知道你是否还有其他的建议要看?没有特别的-有很多好的信息,我想我没有听说过关于这个的任何不好的地方。