Chat-robot that will take input and response in Python
<p>I'm currently trying to create a small version of a chat robot that will respond to different keyword inputs in a terminal. For example, if I write <code>inv</code> it will print out its current inventory and it can look like this:</p>

<pre><code>Item: sword
Place in inventory: 1
Item: axe
Place in inventory: 2
Item: shield
Place in inventory: 3
Item: bow
Place in inventory: 4
Item: flower
Place in inventory: 5
</code></pre>

<p>And that part I have solved. The problem occurs when I'm going to give an input like <code>inv pick hammer</code> or <code>inv drop hammer</code>. Now I have to handle somehow that the same start keyword can occur in multiple cases.</p>

<p>I have created some kind of handler that takes a argument (the input from user) and splits it into a list. Looks something like this:</p>

<pre><code>def splitIntoWords(argOne):
"""
Function that splits list into words
"""
#list to keep and split up the user input
inputList = []
inputList = argOne.split()
#print(str(inputList) + "splitIntoWords")
#term we want to search for
term = "citat"
quitOne = "q"
replyHej = "hej"
replyLunch = "lunch"
inventory = "inv"
invPick = "pick"

#invDrop = "drop"
lenght = len(inputList)
nextWord = inputList[lenght-1]



if term in inputList:
    return term
elif quitOne in inputList:
    return quitOne
elif replyHej in inputList:
    return replyHej
elif replyLunch in inputList:
    return replyLunch
elif inventory in inputList:
    if invPick in inputList:
        return ("q")
    else:
        return inventory
else:
    return result
</code></pre>

<p>As you can see I have started to do and if inside an elif and tried to do multiple checks on the same list, but it doesn't work for me.
Is there any other way I can do check to see it that more than one keyword appears in the list?</p>

<p>I formatted and tested the code and it works. </p>

<pre><code>def splitIntoWords( argOne):

    result = "hej"
    """
    Function that splits list into words
    """
    # list to keep and split up the user input
    inputList = []
    inputList = argOne.split()
    print(str(inputList) + "splitIntoWords")
    # term we want to search for
    term = "citat"
    quitOne = "q"
    replyHej = "hej"
    replyLunch = "lunch"
    inventory = "inv"
    invPick = "pick"

    # invDrop = "drop"
    lenght = len(inputList)
    nextWord = inputList[lenght - 1]

    if term in inputList:
        return term
    elif quitOne in inputList:
        return quitOne
    elif replyHej in inputList:
        return replyHej
    elif replyLunch in inputList:
        return replyLunch
    elif inventory in inputList:
        if invPick in inputList:
            return ("q")
        else:
            return inventory
    else:
        return result

print splitIntoWords("inv pick sword")
</code></pre>

<p>Test</p>

<pre><code>python inventory.py 
['inv', 'pick', 'sword']splitIntoWords
q
</code></pre>

<p>The <code>q</code> above is the expected result. </p>

python list python-3.x