Chatbot for simple questions:
Algorithm:
1. Define a list of predefined questions
and their corresponding answers.
2. Use a loop to continuously prompt
the user for input.
3. Check the user's input against the
predefined questions using conditional
statements (if-else).
4. If a match is found, output the
corresponding answer.
5. If no match is found, output a default
response (e.g., "I didn't understand
that.").
Dataset: None required, as this chatbot
uses predefined rules and doesn't rely
on machine learning or external data.
Libraries:
- Python (built-in)
Code Example:
# Define predefined questions and
answers
questions_answers = {
"hello": "Hi! How can I help you?",
"how are you": "I'm doing well,
thanks!",
"what is your name": "I'm a simple
chatbot.",
# Add more questions and answers as
needed
}
# Loop to continuously prompt user for
input
while True:
user_input = input("User: ")
# Check user input against predefined
questions
for question, answer in
questions_answers.items():
if user_input.lower() == question:
print("Chatbot:", answer)
break
else:
print("Chatbot: I didn't understand
that.")
Inputs:
- User input (text)
Outputs:
- Chatbot response (text)
Conditions:
- User input matches a predefined
question