Chatbot in python that can convert age in words to a number

i am building a chatbot and when i added an input for the chatbot to ask the user for their age i came across a problem what if the user types their age in words like if their age is 14 they can type fourteen or fourteen years old. I wanted to save the input into a variable age so that i can use that variable age later like if i was making a chatbot for a clothing store then depending on the users age i would recommend them some clothing items suited to their age group but now if the user types twelve or twelve years old how will my chatbot interpret what they type in words as a number.
i recently learned about nltk and a little about deep learning in chatbots .

You can create your own interpreter for this, or if you want there’s already a package you can install called word2number that contains a function to do exactly this for you. So if you can guarantee you can strip out the number word you can use this package to do the conversion. Alternatively you can set up the code such that the user is required to input a numeric value. This would require less coding but of course leads to less flexibility.

thank you for the suggestion. I’m still a newbie can you tell me where to download word2number from also i think this would solve the problem if the user inputs like fourteen but what if the user inputs fourteen years old or i am fourteen years old . how will i solve this problem? should i add another variable that checks for a wordform of a number in the input that the user gives and then add that wordform to another variable and then use word2number to convert that variable into a number and then save the number to the variable age.

If you are completing this project on your own computer, then you would run pip install word2number. Solving the problem of filtering out all the possible combinations is very tricky, and requires a significantly long and complicated regex function. If you’re new to regex it’s good to look into, but honestly I would recommend instead of doing all of this, just forcing a numerical input by keeping them in a while loop until the input they respond with can be neatly coerced into a number. Something like this:

while True:
    resp = input('Please input an integer: ')
    try:
        check = int(resp)
        print(check)
        break
    except ValueError:
        print('Please enter a number.')

This tries to coerce the user response to an integer, and prompts the user to enter a number if it fails. This is probably the easiest way, although naturally it does limit the range of inputs that can be taken. Google around and see about using word2number and regex, however if you are still new I’d recommend starting here as regex is intensely complicated for even experienced programmers.

thank you also i will look into regex after i get some experience