Alienbot - again :(


I am again stucked in the Alienbot project, this time step 26/27.

I do believe that the below is correct and working as expected.

def match_reply(self, reply):
    for intent, regex_pattern in self.alienbabble.items():
      found_match = re.match(regex_pattern, reply.lower())
      if found_match and intent == 'describe_planet_intent':
        return self.describe_planet_intent()
      elif found_match and intent == 'answer_why_intent': 
        return self.answer_why_intent()
      elif found_match and intent == 'cubed_intent':
        return self.cubed_intent(found_match.groups()[0])
        return self.no_match_intent() 

The self.cubed_intent method looks like:

def cubed_intent(self, number):
    number = int(number)
    cubed_number = number * number * number
    return f'The cube of {number} is {cubed_number}. Isn\'t that cool?'

The underlying dictionary is

self.alienbabble = {'describe_planet_intent': r'.*\s*your planet.*',
                        'answer_why_intent': r'why\sare.*',
                        'cubed_intent': r'.*cube.*(\d+)'

Now, every time, I try to run the regex, it evaluates to the else statement.

$ python3
Hello, may I know your name please ? q
Hi q, I'm Etcetera. I'm not from this planet. Will you help me learn about your planet? yes
Are there many humans like you? Can you cube the number 3
Inside .no_match_intent()

I do believe that the regex pattern is correct, but unsure, why it does not evaluate to the correct method. I have used return and print, but still it evaluates to .no_match_intent().

Can someone spot my mistake ?


Please post a link to the project so we can read the criteria and instructions.

1 Like

I believe it’s this one linked recently in a question-

With an if statement ending in an else clause one of those clauses will have its “suite” of code executed. Consider how this might perform when within a loop. If unsure maybe step through it line by line in your head or on paper.


Hey @amwn it’s been a little while since you originally posted this question. Could you come back to let us know if the above reply helped you?

1 Like

Hi, I have moved the else statement outside and it works.
Thank you !!

1 Like