Hi,
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])
else:
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 script.py
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 ?
Thanks