【发布时间】:2014-02-25 05:14:56
【问题描述】:
我正在尝试编写一个包含代词、主语(名词)和动词的三字句子的代码。例:我恨你。然后它会识别每个单词(无论是名词、动词还是代词)并记住名词和动词。然后它会以非常明显的方式回复句子,例如: 输入:我讨厌苹果。 回复:你为什么讨厌苹果? 输入:我参加体育运动。 回复:你为什么要运动?
相当简单的东西,但我无法将句子中的每个单词分开,然后将每个单词保存为它们的类型。稍后我将处理专有名词,现在我正在处理大约 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() 函数,如果特定单词被触发,我如何记住哪个?它会以不恰当的时态返回动词这一事实对我来说很好,我稍后会处理! 非常感谢 布拉姆
编辑:忽略numbers = map(int, test.split())
【问题讨论】:
标签: python python-2.7 python-3.x