FAQ: Retrieval-Based Chatbots - Lesson Review

This community-built FAQ covers the “Lesson Review” exercise from the lesson “Retrieval-Based Chatbots”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Build Chatbots with Python

FAQs on the exercise Lesson Review

There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply (reply) below.

If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!
You can also find further discussion and get answers to your questions over in #get-help.

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head to #get-help and #community:tips-and-resources. If you are wanting feedback or inspiration for a project, check out #project.

Looking for motivation to keep learning? Join our wider discussions in #community

Learn more about how to use this guide.

Found a bug? Report it online, or post in #community:Codecademy-Bug-Reporting

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

My chatbot won’t understand my how_to_pay_bill or pay_bill inputs. It just keeps saying it doesn’t understand. Not sure why.

class SupportBot:
negative_responses = (“nothing”, “don’t”, “stop”, “sorry”)

exit_commands = (“quit”, “pause”, “exit”, “goodbye”, “bye”, “later”)

def init(self):
self.matching_phrases = {‘how_to_pay_bill’: [r’.*how.pay bills.’, r’.*how.pay my bill.’], r’pay_bill’: [r’.*want.*pay.*my.*bill.*account.*number.*is (\d+)’, r’.*need.*pay.*my.*bill.*account.*number.*is (\d+)’]}

def welcome(self):
name = input("Hi, I’m a customer support representative. Welcome to Codecademy Bank. Before we can help you, I need some information from you. What is your first name and last name? ")

will_help = input(f"Ok {name}, what can I help you with? ")

if will_help in self.negative_responses:
  print("Ok, have a great day!")


def handle_conversation(self, reply):
while not self.make_exit(reply):
reply = self.match_reply(reply)

def make_exit(self, reply):
for exit_command in self.exit_commands:
if exit_command in reply:
print(“Ok, have a great day!”)
return True

return False

def match_reply(self, reply):
for key, values in self.matching_phrases.items():
for regex_pattern in values:
found_match = re.match(regex_pattern, reply)
if found_match and key == ‘how_to_pay_bill’:
return self.how_to_pay_bill_intent()
elif found_match and key == ‘pay_bill’:
return self.pay_bill_intent(found_match.groups()[0])

return input("I did not understand you. Can you please ask your question again?")

def how_to_pay_bill_intent(self):
return input(“You can pay your bill a couple of ways. 1) online at bill.codecademybank.com or 2) you can pay your bill right now with me. Can I help you with anything else?”)

def pay_bill_intent(self, account_number=None):
return input(f"The account with number {account_number} was paid off. What else can I help you with?")

Create a SupportBot instance

SupportConversation = SupportBot()

Call the .welcome() method