Saturday, 24 May 2025

chat bot using python

 #chatbot

import nltk

import re


def chatbot():

    while True:

        user_input = input("User: ")

        user_input = user_input.lower()

        user_input = re.sub(r'[^\w\s]', '', user_input)

        tokens = nltk.word_tokenize(user_input)


        if 'hello' in tokens:

            print("Chatbot: Hi there!")

        elif 'bye' in tokens:

            print("Chatbot: Goodbye!")

            break

        else:

            print("Chatbot: Sorry, I didn't understand.")


chatbot()