So, I am trying to make a very basic chatbot, and I wanted to create a list of possible user inputs, and then a variable that takes the user input and converts it in a string. So far, so good. What I cannot achieve, and I am not even sure that this is possible or not, is to have my program to check whether the user input includes some phrase from the list and then provide an answer via an if statement.
I tried something like:
a = ["hello","hey","hi"]
command= str(input())
if a in command:
print("Hi!")
Of course, it didn't work, because the "a" had to be a string. What I wanted to happen was for the program to check if the word hello, hey, or hi, is in the command variable, and if it is, to print "Hi!". I want it to work like this would:
if "hello" in command or "hi" in command or "hey" in command print("Hi!")
What can I do about it?
for w in a:
if w in command:
print("Hi!)
for word in a, if command contains the word, then you print "Hi!".
This will work even with strings that start with Hi or Hello and then have some more text that follows.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With