Answer the question
In order to leave comments, you need to log in
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()
Answer the question
In order to leave comments, you need to log in
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 questionAsk a Question
731 491 924 answers to any question