ChatGPT – Create a simple chatbot in Python [Jupyter]

import random
import time

responses = {
“hi”: [“Hello!”, “Hi there!”, “Hey!”],
“how are you”: [“I’m doing well, thank you for asking.”, “I’m good, thanks!”, “I’m fine, how are you?”],
“what is your name”: [“My name is ChatBot.”, “I’m ChatBot.”, “You can call me ChatBot.”],
“bye”: [“Goodbye!”, “Bye!”, “See you later!”],
“what is database”: [“A database is a collection of data that is organized in a way that allows for efficient storage, retrieval, and manipulation of that data.”, “A database is a structured collection of data that is stored and organized in a way that allows for efficient retrieval and manipulation of that data.”],
“mujhy basic php mai hello world ka program likh k do”:[

    '<?php '

    'echo ' " Hello World!; "

    ' ?> '
                                                       ]                                              


# Add more responses here

}

def chat():
while True:
user_input = input(“You: “).lower()
if user_input in responses:
bot_response = random.choice(responses[user_input])
for character in bot_response:
print(character, end=””, flush=True)
time.sleep(0.03) # Adjust typing speed here
print(“\n”) # Add newline after response
elif user_input == “quit”:
print(“Bot: Goodbye!”)
break
else:
print(“Bot: I’m sorry, I don’t understand.\n”)

chat()

Leave a comment