N
N
Nolrox2021-11-27 21:21:39
Bots
Nolrox, 2021-11-27 21:21:39

What to do if the bot does not respond to the command?

I'm building a chatbot with learning.
Like if he does not know some command, then he asks what to answer him, and if you write this command later, he will answer what I told him.

cmds = []

ans = []

inp = input()

ln = len(cmds)

while inp == cmds:
  f = cmds.index(inp)
  print(f'{ans[f]}')
  inp = input()
else:
  print('Я не знаю этой команды. Что мне отвечать?')
  otv = input()
  cmds.insert(ln, inp)
  ans.insert(ln, otv)
  inp = input()

And if I enter what to answer to him, and then I enter this command, then the program process simply ends, and it does not even display any errors. What to do?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
shurshur, 2021-11-28
@shurshur

Judging by the code, you do not understand what you wrote at all.
inp will contain the string entered from the keyboard, cmds - an empty list
Next, inp == cmds is checked. Obviously, an empty list is never equal to a string, so we immediately get into else and execute this block once, after which the program automatically terminates.
Pick up any Python textbook (like Lutz's) and learn the basics. Without understanding the basic things, you will never write anything meaningful at all.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question