Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions week1_projects/yaswanthkumarch/chat_simulator/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Chat Simulator Project

## What the project does
This is a simple command-line chatbot built in Python. It responds to basic greetings, tells the time and date, and can exit the chat on command.

## How to run
1. Run the Python script:



git checkout -b yaswanth-chat-simulator



git add week1_projects/yaswanthkumarch/chat_simulator/
git commit -m "Yaswanth – Chat Simulator Project"
git push origin yaswanth-chat-simulator



This pull request adds a simple command-line Chat Simulator built in Python.

Features include:
- Greeting the user
- Responding to basic questions such as "What's your name?" and "What's the time?"
- Responding differently based on keywords in user input
- Allowing the user to exit the chat by typing keywords like "bye" or "exit"
- Keeping a conversation history stored in a list

The project demonstrates the use of Python syntax, conditional statements, loops, and basic CLI interaction.

Looking forward to feedback and suggestions. Thank you!

[Yaswanth] – Chat Simulator Project
48 changes: 48 additions & 0 deletions week1_projects/yaswanthkumarch/chat_simulator/chat_simulator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import datetime

def greet_user():
print("Hello! I am ChatSim, your friendly chatbot.")
print("You can ask me basic questions or type 'bye' or 'exit' to quit.")

def get_response(user_input):
user_input = user_input.lower()

if "hello" in user_input or "hi" in user_input:
return "Hi there! How can I help you today?"
elif "your name" in user_input:
return "I am ChatSim, your command-line chatbot."
elif "time" in user_input:
now = datetime.datetime.now().strftime("%H:%M:%S")
return f"The current time is {now}."
elif "date" in user_input:
today = datetime.datetime.now().strftime("%Y-%m-%d")
return f"Today's date is {today}."
elif user_input in ["bye", "exit", "quit"]:
return "exit"
else:
return "Sorry, I didn't understand that. Can you ask something else?"

def main():
greet_user()
conversation_history = []

while True:
user_input = input("You: ")
conversation_history.append(f"You: {user_input}")

response = get_response(user_input)
if response == "exit":
print("ChatSim: Goodbye! Have a great day!")
break
else:
print(f"ChatSim: {response}")
conversation_history.append(f"ChatSim: {response}")

# Optional: Save conversation history to a text file
with open("chat_history.txt", "w") as f:
for line in conversation_history:
f.write(line + "\n")


if __name__ == "__main__":
main()