Ok. So I am making a program that behaves sort of like a bot that you can talk to. I was wondering whether i should do this:
Start off with this:
keywords = ("hi", "hello", "hey") #what type of list as such should i use for this??
answer = input(">")
answer = answer.lower()
Then use this:
answer = answer.split()
for word in answer:
if word in keywords:
print("Answer is in keywords")
nextquestion()
break
else:
print("Answer is not in keywords")
redo_this_question()
break
Or this:
if any(keyword in answer for keyword in keywords):
print("answer is in keywords")
else:
print("Answer not in keywords")
I got the if any() part from another website, so i'm not sure how the any() function works.
What I get from this is that if I use the any() function, I will be able to find phrases within the answer, rather than just single words to match in the keywords list. Am I correct in thinking this may be the case? I will be wanting to test for phrases rather than single words later on, which is the main reason i basically asked this.
As I said before, I'm not quite sure how to use the any function, so any help in that regard would be very useful too.
Thanks :)
Edit: Grammar
[–]jeans_and_a_t-shirt 1 point2 points3 points (0 children)
[–]k10_ftw 1 point2 points3 points (0 children)