Python中文
首页
教程
问答
标签
搜索
登录
注册
Python将索引设置为超出范围
回答此问题可获得
20
贡献值,回答如果被采纳可获得
50
分。
<p>我从Python开始学习,在开始学习类之前,我一直做得很好。我正在尝试创建一个聊天机器人,在主类中,函数Python<code>pensar()</code>返回<code>iniciar</code>,因此函数<code>resp()</code>可以将它附加到self.recente列表中。它按必须的方式发生,但是当循环再次到达<code>pensar()</code>时,它不会得到self.recente[-1]。希望有人能帮助我</p> <p><strong>这是课程代码:</strong></p> <pre><code>class IA(): def __init__(self, nome): self.nome = nome self.recente = [] def ouvir(self): iniciar = input('»') iniciar = iniciar.upper() iniciar = iniciar.replace('O ', '') return iniciar def pensar(self, iniciar): if iniciar == 'OI': return 'Ola, qual seu nome?' if self.recente[-1] == 'Olá, qual seu nome?': a = self.pegar_nome() b = self.resp_nome(b) def pegar_nome(self): pass def resp_nome(self, iniciar): pass def resp(self, iniciar): self.recente.append(iniciar) print(iniciar) </code></pre> <p><strong>这是最主要的一个:</strong></p> <pre><code> from Ia import IA tchau = ['TCHAU', 'XAU', 'ATE LOGO', 'ATÉ LOGO', 'ATE MAIS', 'ATÉ MAIS'] while True: a = IA('Joao') b = a.ouvir() if b in tchau: print('Até mais') break c = a.pensar(b) a.resp(c) </code></pre>
0 条评论
分类:
Python问答
请先
登录
后评论
默认排序
时间排序
1 个回答
匿名
1天前
擅长:python、mysql、java
<p>您可以在OOP中编写自变量:</p> <pre><code>>> (self.iniciar) </code></pre> <p>没有<code>self</code>,<code>iniciar</code>是一个全局变量</p>
请先
登录
后评论
针对此问题:
更多的回答
关注
89
关注
收藏
1
收藏,
216
浏览
网友 提问于 2天前
相关Python问题
如何在python中从数据帧列中删除分类值?
8 回答
如何在python中从数据帧列表中删除引号
5 回答
如何在python中从数据帧创建列表
4 回答
如何在Python中从数据帧创建嵌套的JSON
2 回答
如何在Python中从数据帧显示wordcloud
2 回答
如何在Python中从数据帧的时间戳中删除字符
3 回答
如何在Python中从数据帧绘制简单绘图?
1 回答
如何在python中从数据帧行提取具有特定长度的范围?
4 回答
如何在python中从数据帧设置dict中的值
3 回答
如何在Python中从数据库中获得一个结果
7 回答
如何在python中从数据框中绘制分类条形图
3 回答
如何在Python中从数据框中选择特定细节?
1 回答
如何在python中从数据集中删除unicode
4 回答
如何在python中从数据集中删除某些数值?
4 回答
如何在python中从数据集中选择行
2 回答
如何在Python中从数组中删除元素
8 回答
如何在python中从数组中删除单个倒逗号?
1 回答
如何在python中从数组中删除对象?
6 回答
如何在python中从数组中删除引号
5 回答
如何在python中从数组中删除所有最小值
7 回答