- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我 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/
我有这个问题: 我们声称对 float 使用相等测试是不安全的,因为算术运算会引入舍入错误,这意味着两个应该相等的数字实际上并不相等。 对于这个程序,您应该选择一个数字 N,并编写一个程序来显示 1
为什么这个脚本的输出是 5 而不是 8 ? 我认为 -- 意味着 -1 两次。 var x = 0; var y = 10; while ( x
我现在可以从 cmd 窗口中执行的 FFmpeg 过程中读取最后一行。 使用脚本主机模型对象引用此源。 Private Sub Command1_Click() Dim oExec
使用 vlookup,当匹配发生时,我想从匹配发生的同一行显示工作表 2 中 C 列的值。我想出的公式从 C 列表 2 中获取值,但它从公式粘贴在表 3 上的行中获取,而不是从匹配发生的位置获取。 这
我在破译 WCF 跟踪文件时遇到了问题,我希望有人能帮助我确定管道中的哪个位置发生了延迟。 “Processing Message XX”的跟踪如下所示,在事件边界和传输到“Process Actio
我有四个表,USER、CONTACT、CONACT_TYPE 和 USER_CONTACT USER_CONTACT 存储用户具有填充虚拟数据的表的所有联系人如下 用户表 USER_ID(int)|
以下有什么作用? public static function find_by_sql($sql="") { global $database; $result_set = $data
我正在解决 JavaBat 问题并且对我的逻辑感到困惑。 这是任务: Given a day of the week encoded as 0=Sun, 1=Mon, 2=Tue, ...6=Sat,
我正在研究一些 Scala 代码,发现这种方法让我感到困惑。在匹配语句中,sublist@ 是什么?构造?它包含什么样的值(value)?当我打印它时,它与 tail 没有区别,但如果我用尾部替换它,
我正在使用以下代码自行缩放图像。代码很好,图像缩放也没有问题。 UIImage *originImg = img; size = newSize; if (originImg.size.width >
Instruments 无法在我的 iPad 和 iPhone 上启动。两者都已正确配置,我可以毫无问题地从 xcode 调试它们上的代码,但 Instruments 无法启动。 我听到的只是一声嘟嘟
我想用 iPhone 的 NSRegularExpression 类解析此文本: Uploaded652.81 GB 用于摘录上传和652.81文本。 最佳答案 虽然我确实认为 xml 解析器更适合解
我找到了 solution在 Stackoverflow 上,根据过滤器显示 HTML“li”元素(请参阅附件)。本质上基于 HTML 元素中定义的 css 类,它填充您可以从中选择的下拉列表。 我想
这是一个简单的问题,但我是在 SQL 2005 中形成 XML 的新手,但是用于形成如下所示表中的 XML 的最佳 FOR XML SQL 语句是什么? Column1 Column2 -
我在 www.enigmafest.com 有一个网站!您可以尝试打开它!我面临的问题是,在预加载器完成后,主页会出现,但其他菜单仍然需要很长时间才能加载,而且声音也至少需要 5 分钟! :( 我怎样
好吧,我正在尝试用 Haskell 来理解 IO,我想我应该编写一个处理网页的简短小应用程序来完成它。我被绊倒的代码片段是(向 bobince 表示歉意,但公平地说,我并不想在这里解析 HTML,只是
如何使用背景页面来突出显示网站上的某个关键字,无论网站是什么(谷歌浏览器扩展)?没有弹出窗口或任何东西,它只是在某人正在查看的网站上编辑关键字。我以前见过这样的,就是不明白怎么做!谢谢你的帮助。 最佳
我是 Javascript 新手,需要一些帮助。 先看图片: . 积分预测器应用程序。 基本上当用户通过单选按钮选择获胜团队时它应该在积分栏中为获胜队添加 10 分,并且并根据得分高的球队自动对表格进
这是我的情况 - 我要发送一份时事通讯,我试图做的是,当用户单击电子邮件中的链接时,它会重定向到我的网页,然后会弹出一个灯箱,显示视频。我无法在页面加载时触发灯箱,因为您可以在查看灯箱之前转到同一页面
我有这个代码。 ¿Cuanto es ? Ir 我想获取用户输入的“验证码”值。我尝试这个但行不通。有什么帮助吗? var campo = d
我是一名优秀的程序员,十分优秀!