gpt4 book ai didi

python - 我需要一些帮助来查找列表中的列表中的内容(除其他外)

转载 作者:行者123 更新时间:2023-11-30 09:13:15 26 4
gpt4 key购买 nike

我 14 岁(实际上不到一个小时就变成 15 岁了:D),我真的很挣扎。我正在尝试创建一个非常基础的学习人工智能。目前我只是想建立它的框架,帮助它学习新单词的部分,所以有点困惑和粗糙。不管怎样,这个想法是,当它不理解一个单词时,它会询问它是什么,然后如果用户提供的同义词被识别,它会将其添加到该同义词的同义词列表中。不幸的是,我不断遇到错误和问题,现在我很困惑。请帮我看一下。哦,我对其糟糕的结构和其他一切都很糟糕表示歉意:

#standard dictionary

dictionary = {1:"hi",2:"yes",3:"no"}
wordvariations=[[],["yes,Yes"],["no,No"]]


#variables

breaker=0
response = "error"
success=0

#import

from random import choice

#word types

question_words= {"who","what","where","why","when","which","how","whom","Who","What","Where","Why","When","Which","How","Whom"}

#What does that mean?

def what_does_that_mean(new_word):
link_word = input("Sorry, I don't know what that means. Could you tell me? It means the same as the word...\n")
success=0
for current_dict in wordvariations:
if link_word in current_dict == TRUE:
print ("Thanks")
current_dict.append[new_word]
success=1
break
if success == 0:
tryagain = input("Sorry, I don't know what that means either. Would you like to try again? (y/n) \n")
if input == "y":
testword= input("Give me another word \n")
what_does_this_mean(testword)
else: return


#First start

possible_greeting =input("Hey. Nice to meet you.\n")
split_greeting = possible_greeting.split()

for each_word in split_greeting:
if each_word in question_words:
response = "Sorry, I can't answer questions yet"
breaker=1
break
elif (each_word == ("too")):
response = "Thanks"
breaker=1
break
else: pass

if breaker ==1:
pass
else:
yes_no = input("Is that how you usually greet people?\n")
if yes_no == "yes":
wordvariations[1].append(possible_greeting)
elif yes_no=="no":
new_greeting = input("Ok then. How do you often greet people?")
wordvariations[1].append(new_greeting)
else:
what_does_that_mean(yes_no)

#print (response)


#Other stuff

current_greeting = choice(wordvariations[1])
print (current_greeting)

如果任何缩进看起来确实不对劲,我可能把它放在问题框中是错误的。

我真的很感激这里的任何帮助 - 我觉得我在兜圈子。目前,搜索似乎不起作用,因为它从未找到结果。最需要修复的是单词查找功能区域,其余的只是一种启动脚本来让事情继续进行。尝试忽略那些稍后会出现的完全无用的部分。

提前致谢:)

最佳答案

恭喜 jack :D

一些可以让您更轻松的事情

>>> 'How'.lower()
'how'
if word.lower() in word_list: # where word_list contains lower case only

因此您可以通过始终将其变为小写来删除单词的大写/小写版本。

if link_word in current_dir == TRUE:

可以简单地写

if link_word in current_dir:

您还可以使用 bool 值(True/False)代替整数

success = 1 可以改为 success = True,并且有了 bool 值,您可以简单地使用 if success 检查它们

(如果您愿意的话,实际上有一个 for ... else 可以在没有 success 变量 Why does python use 'else' after for and while loops? 的情况下完成您想要做的事情)

current_dict.append[newword] 应为 current_dict.append([newword])current_dict.append(newword)

您还错过了一些调用变量input的操作,例如if input=='y'

我也正在运行 python 2 还是 3?在 python 2 中 input('?') 不是你想要的(它是 raw_input('?')

我认为您会希望 wordvariations 成为问候部分自己的。就像称之为问候一样。 (这样您就不必一直 ...[1])

您写的是 what_does_this_mean 而不是 what_does_that_mean

关于python - 我需要一些帮助来查找列表中的列表中的内容(除其他外),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21742259/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com