-
Notifications
You must be signed in to change notification settings - Fork 0
/
Chat_Bot_Simple.py
36 lines (32 loc) · 1.15 KB
/
Chat_Bot_Simple.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# Initialize conversation state
over = False
def getResponse(ui):
"""Process user input and return a response."""
# Trim whitespace and convert to lowercase
ui = ui.strip().lower()
# Split the input into words
words = ui.split(" ")
# Respond based on specific keywords
if "thank" in words:
return "You're welcome!"
elif "hello" in words:
return "Hello! How can I assist you today?"
elif "how" in words and "you" in words:
return "I'm just a program, but I'm here to help you!"
else:
return "Sorry, I couldn't understand you."
def Conversate():
"""Handle the conversation flow."""
global over
if not over:
ui = input(" You: ") # Get user input
if ui.lower() == "exit":
over = True
print("Thank you for using me.")
else:
response = getResponse(ui) # Get response based on user input
print(" Bot:", response) # Print the bot's response
Conversate() # Recursion to continue the conversation
# Start the conversation
print("Hello user! Type 'exit' to end the conversation.\n")
Conversate()