Search code examples
pythonxmlpython-3.xaiml

Except method python pyAIML


My AIML pattern "HI" bot answer "HI TOO"

My code

text = input.("ASK?")
if text == text:
   try:
      print(k.respond(text))
   except:
      print('NOT FOUND')

if i input wrong pattern like "WRONG" except massage doesnt apper


Solution

  • aiml will not throw any exception even if the match is not found it just replies empty string. so instead of try and except block use if else.

    text = input.("ASK?")
    if text == text:
       if k.respond(text) != '':
          print(k.respond(text))
       else:
          print('NOT FOUND')