-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
47 lines (32 loc) · 1.03 KB
/
Copy pathmain.py
File metadata and controls
47 lines (32 loc) · 1.03 KB
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
38
39
40
41
42
43
44
45
46
47
from chatbot import Chatbot
def get_user_input():
"""Get valid input from the user."""
while True:
user_input = input("You: ").strip()
if user_input:
return user_input
print("PyBot: Please enter a message.")
def main():
"""Run the chatbot application."""
bot = Chatbot("PyBot")
print("=" * 40)
print(" Welcome to PyBot")
print("=" * 40)
print("Type 'help' to see what I can do.")
print("Type 'history' to view the conversation.")
print("Type 'bye' to exit.")
print()
while True:
try:
user_input = get_user_input()
response = bot.respond(user_input)
print(f"PyBot: {response}")
if user_input.lower() in ["bye", "goodbye", "exit", "quit"]:
break
except KeyboardInterrupt:
print("\nPyBot: Goodbye!")
break
except Exception as error:
print(f"PyBot: An unexpected error occurred: {error}")
if __name__ == "__main__":
main()