Simple ChatBot
# Define a dictionary with predefined questions and answers
Chatbot_responses = {
“hello”: “Hi! How can I help you?”,
“hi”: “Hello! What can I do for you?”,
“how are you”: “I’m doing well, thanks!”,
“what is your name”: “I’m a simple chatbot.”,
“exit”: “Goodbye! Have a great day!”
# Function to handle user input and respond accordingly
Def chatbot_response(user_input):
User_input = user_input.lower()
For question, answer in chatbot_responses.items():
If user_input == question:
Return answer
Return “I didn’t understand that.”
# Main loop to continuously prompt user for input
While True:
User_input = input(“User: “)
If user_input.lower() == “exit”:
Print(“Chatbot: Goodbye! Have a great day!”)
Break
Print(“Chatbot:”, chatbot_response(user_input))
Project Output:
This code will create a simple chatbot that responds to predefined questions. When
you run the code, it will continuously prompt you for input. If you type one of the
predefined questions, it will respond with the corresponding answer. If you type
something else, it will respond with “I didn’t understand that.” To exit the chatbot,
type “exit”.
Example Conversation:
User: hello
Chatbot: Hi! How can I help you?
User: how are you
Chatbot: I’m doing well, thanks!
User: what is your name
Chatbot: I’m a simple chatbot.
User: exit
Chatbot: Goodbye! Have a great day!
```