Untitled
unknown
plain_text
a month ago
1.4 kB
3
Indexable
import time import datetime import pytz def chatbot_calling(user_input): user_input = user_input.lower() if "hello" in user_input or "hi" in user_input: return "Hello! How can I assist you today?" elif "how are you" in user_input: return "I'm just a computer program, but I'm here to help!" elif "what is your name" in user_input: return "I'm a chatbot. You can call me Ramanan." if "time" in user_input: current_time_utc = datetime.datetime.now(pytz.utc) desired_timezone = pytz.timezone('Asia/Kolkata') current_time_local = current_time_utc.astimezone(desired_timezone) formatted_time = current_time_local.strftime("%I:%M:%S %p") return f"The current time is {formatted_time}." elif "date" in user_input: current_date = time.strftime("%Y-%m-%d") return f"Today's date is {current_date}." elif "bye" in user_input or "goodbye" in user_input: return "Goodbye! Have a great day!" else: return "I'm sorry, I didn't understand that. Can you please rephrase?" def chatbot(): print("Chatbot: Hello! Type 'bye' or 'exit' to exit.") while True: user_input = input("You: ") response = chatbot_calling(user_input) print(f"Chatbot: {response}") if user_input.lower() in ["bye", "exit"]: break chatbot()
Editor is loading...
Leave a Comment