-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
37 lines (33 loc) · 1.22 KB
/
main.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
37
# Import necessary libraries
import random
from typing import Dict
# Define responses for different prompts
responses : Dict[str,list[str]]= {
"hello": ["Hello!", "Hi there!", "Hey!"],
"how_are_you": ["I'm doing well, thank you!", "I'm good. How about you?", "All good!"],
"bye": ["Goodbye!", "See you later!", "Take care!"],
"default": ["I'm sorry, I didn't quite catch that.", "Could you please rephrase?", "I'm still learning!"]
}
# Function to get a response based on user input
def get_response(user_input):
user_input = user_input.lower()
if "hello" in user_input:
return random.choice(responses["hello"])
elif "how are you" in user_input:
return random.choice(responses["how_are_you"])
elif "bye" in user_input:
return random.choice(responses["bye"])
else:
return random.choice(responses["default"])
# Main loop for chatbot interaction
def main():
print("Chatbot: Hello! How can I assist you today?")
while True:
user_input = input("You: ")
if user_input.lower() == "exit":
print("Chatbot: Goodbye!")
break
response = get_response(user_input)
print(f"Chatbot: {response}")
if __name__ == "__main__":
main()