The task is to take an inputted string (query
) and see if any of the words match the keys in a dictionary (rsp_dict
). Simple.
words = query.split()
for each in words:
if each in rsp_dict:
print(rsp_dict[each])
But what I can't figure out, is how to make it print out a phrase if none of the words match keys from the dictionary. I've tried a million different methods, but I always end up with the phrase printing for every False value, rather than just the once.
I'm really hoping to learn from this so any help or guidance is really appreciated. Please also feel free to suggest edits on how I've phrased this question.