我试图用这个代码翻译我是杰森,但当我使用它时,它不会打印出来任何东西,除非我像hello这样做一个字,然后它打印出guten标签,但就是这样。另外,我不能把输入数据转换成小写,以便能够将其与字典进行比较。我能做什么来使代码工作?
name = input("Please enter your name\n")
data = [input("Please enter sentence\n")]
data = data.lower() #to make sentence lowercase to be able to compare it to the words in the dictionary
dictionary = {"hello": "hallo", "i" : "ik", "am" : "ben"}
dictionary[name] = name
for word in data:
if word in dictionary:
print (dictionary[word],)
这是回溯
*请输入您的姓名
杰森
请输入句子
我是杰森*
^{pr2}$
你根据用户的回答列出了一个列表
列表没有
^{pr2}$lower
方法。首先获取用户的响应并将其转换为小写。在
然后在空白处split the string获取单个单词的列表。在
相关问题 更多 >
编程相关推荐