Alienbot - What's wrong with my code

# importing regex and random libraries import re import random class AlienBot: # potential negative responses negative_responses = ("no", "nope", "nah", "naw", "not a chance", "sorry") # keywords for exiting the conversation exit_commands = ("quit", "pause", "exit", "goodbye", "bye", "later") # random starter questions random_questions = ( "Why are you here? ", "Are there many humans like you? ", "What do you consume for sustenance? ", "Is there intelligent life on this planet? ", "Does Earth have a leader? ", "What planets have you visited? ", "What technology do you have on this planet? " ) def __init__(self): self.alienbabble = {'describe_planet_intent':r'.*describe your planet.*', 'answer_why_intent':r'.*why are your planet.*', 'cubed_intent':r'' } # Define .greet() below: def greet(self): = input('What the ■■■■ is your name?') will_help = input(f'Hi {}, I\'m not from this planet. Will you help me learn about your planet?') if will_help in self.negative_responses: print('Ok, have a nice Earth day!') return # Define .make_exit() here: def make_exit(self, reply): for exit_command in self.exit_commands: if exit_command in reply: print("Ok, have a nice Earth day!") return True return False # Define .chat() next: def chat(self): reply = input(random.choice(self.random_questions)).lower() while not self.make_exit(reply): reply = input(self.match_reply(reply)) # Define .match_reply() below: def match_reply(self, reply): for key, values in self.alienbabble.items(): for regex_pattern in values: found_match = re.match(regex_pattern, reply.lower()) if found_match and key == 'describe_planet_intent': return self.describe_planet_intent() elif found_match and key == 'answer_why_intent': return self.answer_why_intent() elif found_match and key == 'cubed_intent': return self.cubed_intent() else: return 'I don\'t understand. Please ask again.' # Define .describe_planet_intent(): def describe_planet_intent(self): responses = ( "My planet is a utopia of diverse organisms and species.", "I am from Opidipus, the capital of the Wayward Galaxies." ) return random.choice(responses) # Define .answer_why_intent(): def answer_why_intent(self): return "Inside .answer_why_intent()" # Define .cubed_intent(): def cubed_intent(self, number): return "Inside .cubed_intent()" # Define .no_match_intent(): def no_match_intent(self): return "Inside .no_match_intent()" # Create an instance of AlienBot below: bot1 = AlienBot() bot1.greet()

Hi, my problem is no matter what question I ask the bot, it will match me to the ‘describe_planet_intent’.

Why is that and how can I fix that?

Set yourself a little crumb-trail of logic.

You know it’s always triggering one bit of logic.
Use an f-string to display what the state of the parameters is right before the logical statement (that the logic calculates). Take that info and work backwards.

For example

def fn(a, b):
   print(f'Right before a<b the status of a is: {a} and status of b is: {b}')
   if (a < b):
      #do something

Then, either the logical statement has to be adjusted, or I have to make sure that my a, b, are coming in correctly.