Problem with alienbot project

OK so I did the project, but it seems like I am having an issue where the only responses I get go straight to the no match intent. I did find another thread about this, but I don’t think I understood the solution. Something about the no_match_intent() going outside the for loop. I’m not sure what to do with it. Can someone please tell me what I am doing wrong here?

1 Like

I’m afraid I’ve not gone through your code in detail but I believe you use an if statement to control the flow for that section. Have you made sure any expressions actually evaluate to True? An additional print or similar might help you to see what section of your code is actually being executed.

To hazard a guess I’d have a very close look at the re.match function and note what it states regarding re.match vs.

Delete the else statement and put the return on the same intent as the for-loop initialization. This fixes the code. But I cannot really explain why so, sorry :smiley:

I’m not sure what changes you made but I’m glad to hear it worked. Be careful with your use of re.match though. Should it fail to find a match it always returns None. If you use then used it in an if statement that part of the expression would always be False, bool(None) == False. It sounds like you re-ordered the way your control flow works at this point so that it now behaves but I think it’s likely that what affected your previous code was this issue. It might not have been the only issue but it probably caused the else statement to be met far too often.

Putting a debug print(key) before the if block should give you a sense of what is happening. The project instructions/hint on this part of the project are misleading but provide an opportunity to learn how to track down bugs. :slight_smile:

My Observations

The no_match_intent should only be returned if there is no match after looping on all of the intents. If you follow the instuctions/hint and put the else block in the for loop it will only check for a match on the first intent and if not found, will return the no_match_intent.

1 Like