Introduction
A chatbot in Python is a software application built with the Python programming language that simulates human-like conversation via text.
A chatbot uses natural language processing (NLP) techniques and, optionally, machine learning to interpret the user’s input, determine intent, and respond accordingly. There are two primary types of chatbots implemented in Python: rule-based chatbots and AI-powered/conversational chatbots. Rule-based bots work via predefined conditional logic and scripted responses, whereas AI-powered bots leverage NLP, intent classification, and sometimes generative models to derive responses.
But our project is a simple rule-based chatbot, which is a beginner practice for learning Python programming. This project simply relies on user input. Our chatbot project is using Python version 3. Python is a general-purpose high-level programming. It is useful for developing desktop GUIs, websites, and web apps. Chatbots built with Python are widely used in customer service, e-commerce, healthcare, education, and internal business tools: they provide 24/7 availability, fast responses, and can scale to many users.
When you execute the project, you will see a set of questions in the command line. The chatbot will ask a set of questions, and you have to answer them. You must start the conversation by answering the question asked. It is an entertainment-based project. We will be explaining every code used for building a chatbot in this article.
Python is suited for this project development for several reasons:
- Ease of Use
- Extensive Libraries
- AI and Machine Learning Support
- Cross-Platform Compatibility
- Community Support

Types of chatbots
While talking about chatbots, let’s understand different types of chatbots too. There are three types of chatbots respectively.
Rule-based chatbots
They rely on pre-defined discussion flows and decision trees. They only respond when the user’s input matches certain patterns or keywords. These bots are easy to create and great for performing structured tasks like FAQs, booking confirmations, and step-by-step instructions. However, they are unable to understand natural language or context beyond their programmed rules, limiting their adaptability.
AI-powered chatbots
The AI-powered chatbot interprets human intent and context through natural language processing (NLP) and machine learning. They can handle unstructured talks and respond to new inquiries by learning from previous exchanges. These bots are more complex, with dynamic and human-like replies, making them ideal for industries such as customer service, healthcare, and e-commerce.
Hybrid chatbots
Hybrid chatbots combine the benefits of both systems, using rule-based workflows for predictable questions and AI capabilities to analyze complicated input. This dual approach assures both accuracy and flexibility, allowing businesses to automate effectively while retaining conversational intelligence.
Explanation of the code
This is how our code and its components work. You can customize this code and add more questions if you want the chatbot to be more interactive and engaging. By expanding the question list and improving logic, you can make the chatbot feel more intelligent and personal.
Importing Libraries
import time import random
time: Used to pause the program briefly (time.sleep()) to make conversations feel natural.random: Used to select random responses or choices from lists.
Greeting the User
name = input("Hello, what is your name? ")
time.sleep(2)
print("Hello " + name)
- Asks for the user’s name.
- Waits 2 seconds before greeting back using the entered name.
Asking About Feelings
feeling = input("How are you today? ")
time.sleep(1)
if "good" in feeling:
print("I'm feeling good too!")
else:
print("I'm sorry to hear that!")
- Takes user input for their mood.
- If the word “good” is in the input, the chatbot responds positively. Otherwise, it gives a sympathetic message.
Favorite Colour
favcolour = input("What is your favourite colour? ")
colours = ["Red","Green","Blue"]
time.sleep(1)
print("My favourite colour is " + random.choice(colours))
- Asks for the user’s favorite color.
- The chatbot then randomly picks one color from a list and says it’s its favorite.
Asking About Activities
mood = input("What are you doing today? ")
mood = ["dancing", "reading", "playing", "watching TV", "hiking"]
time.sleep(1)
print("I feel like " + random.choice(mood) + " today")
- Asks what the user is doing, but then overwrites the variable
moodwith a list of activities. - Picks a random one and says it feels like doing that.
(Note: overwriting the variable removes the user’s input — this is a logical mistake.)
Asking About Love Life
love=input("Do you have a girlfriend? ")
love = ["Yes", "No"]
time.sleep(1)
input("cool")
- Asks a personal question, then reassigns
loveto a list. - Uses
input("cool")which doesn’t store input — it just pauses until the user presses Enter.
(Again, a logical error: user input is ignored.)
Favorite Food
food = input("Which food type do you like most? ")
food=["Asian", "Japanese", "Italian", "Chinese", "Latin"]
time.sleep(1)
print("I mostly like " + random.choice(food))
- Asks about food preferences, then overwrites
foodvariable with a list and picks one randomly.
Favorite Sport
sport = input("Which sport do you love to watch the most? ")
sport=["cirket", "Baseball", "Soccer", "Rugby", "Athletics"]
time.sleep(1)
print("I love to watch " + random.choice(sport))
- Similar structure: asks the user, ignores their answer, and prints a random favorite sport.
- “cirket” is likely a typo for “cricket.”
Fun Facts and Trivia
peak = input("Do you know the height of world's tallest mountain? ")
time.sleep(1)
print("8848")
print("Anyone can answer that.")
- A quick quiz where the bot ignores the user’s answer and prints the height of Mount Everest.
planet = input("How many planet are there in this solar system")
time.sleep(1)
print("I guess there are 8 planets")
- Prints the correct fact regardless of the user’s input.
Horoscope and Exercise
horscope = input("What is the name of your horscope? ")
horscope=["Leo", "Cancer", "Capricon", "Pisces", "Virgo"]
time.sleep(1)
print("My horscope name is " + random.choice(horscope))
- Asks for user’s horoscope but overwrites it, then picks a random one.
(Also contains a typo: “Capricon” → “Capricorn”)
exe = input("How many sit up can you do? ")
exe=["15", "34", "25", "40", "50"]
time.sleep(1)
print("I can do around " + random.choice(exe))
- Asks how many sit-ups the user can do and responds with a random number.
Goodbye Message
tired = input("I am feeling tired today.")
time.sleep(1)
print("See you! Have a nice day.")
- Ends the chat politely after the final statement.
Benefits of chatbots
- 24/7 Availability: Chatbots work round-the-clock without downtime.
- Cost Efficiency: Reduces the need for large customer service teams.
- Scalability: Easily handles thousands of users simultaneously.
- Personalization: Uses stored data to deliver customized responses.
- Increased Engagement: Keeps users active with quick, interactive replies.
- Integration Capability: Works seamlessly with websites, apps, and CRMs.
- Data Collection: Gathers valuable customer insights for analytics and improvement.

Great content, thanks for posting.