Skip to content

Commit 5ee36e0

Browse files
committed
Task_7 chatbot completed
1 parent 225f588 commit 5ee36e0

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

Chauhan_Shyam_R/Task_7/chatbot.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Enhanced rule-based chatbot with more responses
2+
import random
3+
4+
# Dictionary of predefined responses
5+
responses = {
6+
"hi": "Hello! How can I assist you today?",
7+
"hello": "Hi there! How can I help?",
8+
"how are you": "I'm doing well, thank you for asking!",
9+
"what can you do": "I can provide information, answer questions, or just chat with you.",
10+
"bye": "Goodbye! Have a great day!",
11+
"thank you": "You're welcome!",
12+
"default": "I'm sorry, I didn't quite understand that. Could you please rephrase?",
13+
"weather": "The weather today is sunny with a high of 25°C.",
14+
"time": "It's currently 2:30 PM.",
15+
"help": "Sure, I can help! What do you need assistance with?",
16+
"who are you": "I am a chatbot designed to assist you. How can I help today?",
17+
"what is your name": "I don't have a name, but you can call me Chatbot!",
18+
"who created you": "I was created by OpenAI using natural language processing techniques.",
19+
"where are you from": "I exist in the digital realm, here to assist you wherever you are!",
20+
"tell me a joke": "Why don't skeletons fight each other? They don't have the guts!",
21+
"tell me a fact": "Did you know that honey never spoils? Archaeologists have found pots of honey in ancient Egyptian tombs that are over 3,000 years old and still perfectly edible!",
22+
"what's up": "Not much, just here to assist you!",
23+
"how old are you": "I don't have an age. I exist to help you whenever you need assistance!",
24+
"what are you doing": "I'm here, ready to assist you with any questions or information you need!",
25+
"tell me about yourself": "I am a chatbot created to assist users with information and questions. How can I assist you today?",
26+
"good morning": "Good morning! How can I assist you today?",
27+
"good afternoon": "Good afternoon! How can I assist you today?",
28+
"good evening": "Good evening! How can I assist you today?"
29+
}
30+
31+
# Function to generate a response
32+
def generate_response(user_input):
33+
input_lower = user_input.lower()
34+
if input_lower in responses:
35+
return responses[input_lower]
36+
else:
37+
return responses["default"]
38+
39+
# Main loop to run the chatbot
40+
print("Welcome to the Chatbot!")
41+
print("Type 'bye' to exit.")
42+
while True:
43+
user_input = input("You: ")
44+
if user_input.lower() == 'bye':
45+
print(generate_response(user_input))
46+
break
47+
else:
48+
print("Bot:", generate_response(user_input))

0 commit comments

Comments
 (0)