0
I was creating/trying to create a python chat bot, so far so good. But when I use my function that returns the robot’s answer it returns None! I don’t know how to fix...
def responder(conversa1, posicao): #conversa1 significa o que o usuário digitou. A posição esta definida como 1 por padrão
a = open('conversas.txt', 'r')
for linha in a.readlines():
if conversa1 == linha:
resultado = linha
res = resultado.split('= ')[posicao].strip('\n')
return res
Important to say that the answers are saved in a txt file
oi= oi tudo bem?
ola= ola para voce tambem
tudo bem?= tudo bem sim, e voce?
tudo= que legal
NOTE: no if I tried to replace "==" with "in" but when I do this it shows the wrong robot’s answer, I don’t know why.
Hi, I just did that (put if inside the for) in my code and the error persists
– user186161
out of the place a Return 'conversa1 is different from line'
– Guilherme Lima
@Rcoletto changed the answer to Voce test again.
– Guilherme Lima
I just put the Return 'conversa1 is not equal to the line' and now it just returns me this.
– user186161
Exactly the problem is in IF conversa1 == line, use a Debugger tool to see the values of each variable and you will see that they really are different.
– Guilherme Lima
What do I do in this case? I debug the code but it wouldn’t solve right?
– user186161