我需要一些帮助来修正我的代码

2024-06-07 04:46:23 发布

您现在位置:Python中文网/ 问答频道 /正文

我需要从一种语言翻译成另一种语言。我做错了什么?你知道吗

language={}
language = {"Bounjour" : 'Hello',
            "Comment allez vous?" : 'How are you?',
            "Aurevoir" : 'Good Bye'

#User input
print 'Bounjour, Comment Allez vous, Aurevoir'
phrase = raw_input('Please enter a phrase to translate: ')


#result
print "Your sentence in English: ",
for phrase in language:
    translates = language[words]
    print translates

Tags: in语言helloinputcommentlanguagearehow
1条回答
网友
1楼 · 发布于 2024-06-07 04:46:23

我看到三个错误:

  1. 用户的输入保存在名为phrase的变量中,但是for循环将该变量用作其迭代器,因此用户输入被丢弃。

  2. words没有在任何地方定义。

  3. translates没有在任何地方定义。

但除了这些错误之外,您甚至不需要循环;只需打印language[phrase]。你知道吗

相关问题 更多 >