我想写代码,需要一个代词,主体(名词),和动词的三个措词句妥协。例如:我讨厌你。然后它会识别每个单词(它是一个名词,动词还是代词)并记住名词和动词。然后它会以非常明显的方式回复这个句子,例如: 输入:我讨厌苹果。 回复:你为什么讨厌苹果? 输入:我玩运动。 回复:你为什么要玩体育?如何解构和回复3条款的句子
很简单的东西,但我有麻烦拆分句子中的每个单词,然后保存每个单词,他们是哪种类型。以后我会处理专有名词,现在我正在处理一个约2000个名词的简单列表。
from nouns import nouns_list
from adjectives import adjectives_list
from verbs import verbs_list
from adverbs import adverbs_list
from pronouns import pronouns_list
test = raw_input("Please input a fruit: ")
words = test.split()
#numbers = map(int, test.split())
#use later!
def word_identify(words):
for word in words:
if word in nouns_list:
print words + " is a noun!"
word == noun
elif words in verbs_list:
print words + " is a verb!"
word == verb
elif words in pronouns_list:
print words + " is a pronoun!"
word == pronoun
elif words in adjectives_list:
print words + " is an adjective!"
word == adjective
elif words in adverbs_list:
print word + " is a adverb!"
word == adverb
elif words == 'i' or words == "I":
print "This is the I pronoun!"
word == 'you'
else:
print "Word " + words + " not identified!"
return -1
return 1
while word_identify(test) > 0:
test = raw_input("Please input a fruit: ")
最后,我只是打印一个简单的打印“为什么”+动词+名词+'?' 基本上我问我如何正确使用.split()函数,我如何记住哪个特定的单词被触发?它会以不恰当的时态回复一个动词的事实对我来说很好,我会在稍后处理! 非常感谢 Braam在
编辑:忽略numbers = map(int, test.split())
这非常有帮助!唯一的问题是,现在它不输出任何东西!我查看了代码,我不知道为什么,因为打印功能确实存在。 – user146929
您必须发布一些代码,否则我们看不到问题。 – tsroten
如果您的问题已解决,请选择一个标记为正确的答案。 – tsroten