0% found this document useful (0 votes)
4 views2 pages

Chat Bot Code

The document describes a simple chatbot program that responds to predefined questions with specific answers. It continuously prompts the user for input and provides responses based on the user's input, including an exit option. If the input does not match any predefined questions, the chatbot replies with 'I didn’t understand that.'

Uploaded by

whowhawtf
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views2 pages

Chat Bot Code

The document describes a simple chatbot program that responds to predefined questions with specific answers. It continuously prompts the user for input and provides responses based on the user's input, including an exit option. If the input does not match any predefined questions, the chatbot replies with 'I didn’t understand that.'

Uploaded by

whowhawtf
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

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!

```

You might also like