A beginner-friendly rule-based chatbot built with Python to practice functions, dictionaries, loops, conditions, user input, and the
datetimemodule.
Rubi is a simple command-line chatbot that interacts with the user using predefined rules and responses.
The chatbot can:
- ๐ Greet the user based on the current time
- ๐ง Ask for and use the user's name
- ๐ฌ Respond to predefined questions
- ๐ง Match keywords from user input
- ๐ Continue the conversation using a loop
- ๐ Exit when the user types
bye
This project was created as part of my journey to strengthen my Python fundamentals through hands-on projects.
| Feature | Description |
|---|---|
| ๐ Time-based Greeting | Morning, afternoon, evening, and night greetings |
| ๐ค User Name | Takes the user's name at startup |
| ๐ฌ Rule-Based Responses | Uses predefined chatbot responses |
| ๐ Keyword Matching | Finds matching keywords in user questions |
| ๐ Continuous Chat | Uses while loop for conversation |
| ๐ช Exit Command | Type bye to exit |
| ๐ Dictionary Memory | Stores chatbot questions and responses |
- Python 3
datetimemodule- Python Dictionaries
- Functions
if / elif / elseforloopwhileloop- String methods
- User input
The chatbot follows a simple rule-based flow:
๐ค User
โ
โผ
Enter Name / Question
โ
โผ
Convert Input to Lowercase
โ
โผ
Check Dictionary Keywords
โ
โโโโโโโโโดโโโโโโโโโ
โ โ
Match No Match
โ โ
โผ โผ
Return Response Default Response
โ โ
โโโโโโโโโฌโโโโโโโโโ
โผ
Continue Conversation
โ
โผ
Type "bye"
โ
โผ
๐ Exit
rule-based-python-chatbot/
โ
โโโ rubi_chatbot.py
โโโ README.md
โโโ screenshots/
โโโ chatbot-start.png
โโโ chatbot-conversation.png
git clone https://github.com/Annu1528/Rubi---Rule-Based-Python-ChatBotcd rule-based-python-chatbotpython rubi_chatbot.pySwagat hai! Enter your name: Anushka
Good Afternoon! Anushka
Namaste! Welcome to Rubi, Your Rule Based ChatBot
You can ask me basic questions. Type 'bye' to exit from the bot
Please ask your question: hello
Bot Response: Hi welcome. How can I help you?
Please ask your question: how are you
Bot Response: I am very fine, ThankYou
Please ask your question: motivate me
Bot Response: Keep going. Every bug of your project makes you a better developer.
Please ask your question: bye
Bot Response: Bye! Have a great day!
Rubi stores its responses inside a Python dictionary:
responses = {
"hello": "Hi welcome. How can I help you?",
"how are you": "I am very fine, ThankYou",
"who are you?": "I am a smart AI ChatBot",
"motivate me": "Keep going. Every bug of your project makes you a better developer",
"happy": "Great to hear that!"
}The chatbot then checks whether a keyword exists inside the user's question:
for eachKey in responses:
if eachKey in UserQuestion:
return responses[eachKey]This makes Rubi a rule-based chatbot rather than a machine-learning chatbot.
This project helped me practice:
name = input(...)
presentHour = datetime.datetime.now().hourif 5 <= presentHour < 12:
...
elif 12 <= presentHour < 17:
...
else:
...def getResponseOfBot(UserQuestion):
...responses = {
"hello": "...",
"happy": "..."
}while True:
...and:
for eachKey in responses:
...UserQuestion.lower()The main goal of this project was not to build a complex AI system.
The goal was to understand how basic Python concepts can work together to build a small, functional application.
Through this project, I practiced:
- Writing reusable functions
- Working with dictionaries
- Handling user input
- Using loops
- Applying conditional logic
- Using Python modules
- Debugging syntax and logic errors
- Structuring a small Python project
Planned improvements for Rubi:
- Add more conversation rules
- Add
helpcommand - Add current date and time responses
- Add calculator functionality
- Improve keyword matching
- Add better error handling
- Store conversation history
- Add a simple GUI
- Eventually experiment with an actual AI/API-based chatbot
During development, I encountered and fixed issues related to:
- Case-sensitive variable names
- Dictionary access syntax
- Loop control using
break - Ordering of conditions
- Handling user input
- Running the correct Python file
These debugging experiences were an important part of building the project.
Anushka
Learning Python through practical projects and gradually building towards Cloud, DevOps, and automation.
If you found this project useful, consider giving the repository a โญ.
More Python projects coming soon! ๐
Status: ๐ข Completed โ Version 1.0
Type: Beginner Python Project
Category: Rule-Based Chatbot
