Question: Chatbot help. Only list/string/tuple functions please, no libraries or dictionaries. Allow the user to enter any freeform text input for conversation. Analyze their text for
Chatbot help. Only list/string/tuple functions please, no libraries or dictionaries.
Allow the user to enter any freeform text input for conversation. Analyze their text for the most frequent word(s).
If the most frequent word(s) are present in at least one of the poems, use that poem as the basis for your chatbots response. Select the poem that has the highest occurrence of the word the user used most frequently. If there is more than one word with the same number of occurrences, (e.g. a frequency tie), the longest word wins use the longest word (in terms of len()). There are pre-formed responses (in the RESPONSES list) in the starter code data file. Pick a random response from this list and replace the {poet} and {poem} tags with the data from the poem list given to you in that same file.
If there are no words that match in any of the poems given, print a default message: Thats interesting. I dont quite know what to say
Exit the chatbot when the user enters the "I'm finished talking to you commend": /quit
Handle two special cases: me-or-you: If there are no other matching words from the user input, handle the special case of when the user speaks of themselves OR when the user talks about you (the chatbot).
POEMS = [["Maya Angelou", "You may write me down in history with your bitter, twisted lies; You may trod me in the very dirt but still, like dust, I'll rise"], \ ["Nikki Giovanni", \ "I was born in the Congo. I walked to the Fertile Crescent and built"\ " the Sphinx. I designed a Pyramid so tough that a star that glows"\ " every one hundred years falls into the center giving divine perfect light."\ " I am bad."], ["Langston Hughes", \ "Hold fast to dreams. For if dreams die. life is a broken-winged bird."\ " That cannot fly."], ["Ashley Odilia Armand", \ "Skin, I'm in love with the way you carry the blood that keeps me sane,"\ " and, at times, chaotic."]]
RESPONSES = ["That's interesting. As {poet} has written: '{poem}'", "I was thinking something similar! In fact, I just read {poet}'s"\ " poem about that topic. They wrote: '{poem}'", "I'm speechless. {poet} wrote about that when they said: '{poem}'", "Do you read poetry? Did you know {poet} said the same thing: '{poem}'"]
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
