Nitheesh
Nitheesh
COMPUTER SCIENCE
PROJECT 2024-25
AI CHATBOT USING PYTHON
DONE BY
NITHEESH H (12120)
XII A
ACKNOWLEDGEMENT
I would like to thank the almighty whose blessings enlightened me
to accomplish my project successfully. His might gave me courage,
patience, good concentration and strength through my endeavor.
SOFTWARE
System Overview:
Modules:
random
Used for generating random choices from a list ofresponses.
re (Regular Expressions)
Used for pattern matching to identify greetings andfarewells in the user
input.
Sub-modules:
random.choice()
re.search()
3
4 # Basic responses for greeting and farewell
5 greetings_responses = ["Hello! How can I help youtoday?",
"Hi there! What would you like to know?", "Hey! How's it
going?"]
6 farewell_responses = ["Goodbye!", "Take care!","See
you later!"]
7
8 # Function to process user input and respond
accordingly
9 def chatbot_response(user_input):
10 user_input = user_input.lower()11
12 # Greeting intent
13 if re.search(r"(hello|hi|hey)", user_input):
14 return random.choice(greetings_responses)
15
16 # Farewell intent
17 elif re.search(r"(bye|goodbye)", user_input):
18 return random.choice(farewell_responses)
19
20 # Default response
21 else:
22 return "I'm sorry, I didn't understand that. Canyou please
ask in a different way?"
23
24 # Chatbot conversation loop
25 print("Chatbot: Hello! I'm a simple chatbot. Type'bye' to
exit.")
26 while True:
27 user_input = input("You: ")
28
29 # If the user types 'bye', exit the conversation
30 if "bye" in user_input.lower():
31 print("Chatbot: "+ random.choice(farewell_responses))
32 break
33 else:
34 response = chatbot_response(user_input)
35 print("Chatbot: " + response)
OUTPUT
BIBILOGRAPHY